• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Vlookup for filtered data in VBA|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Vlookup for filtered data in VBA|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosVlookup for filtered data in VBA
sp_PrintTopic sp_TopicIcon
Vlookup for filtered data in VBA
Avatar
Arunachal Jois
Member
Members
Level 0
Forum Posts: 17
Member Since:
August 3, 2020
sp_UserOfflineSmall Offline
1
August 3, 2020 - 3:58 pm
sp_Permalink sp_Print

Hello everyone
I need help for how to perform Vlookup for filtered data in VBA 

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
August 3, 2020 - 4:08 pm
sp_Permalink sp_Print

Hi,

If data is filtered, for example in a table, VLOOKUP still returns the same data.  Filtering has no effect.

Maybe if you explain what you are trying to do we can find a solution.  Please supply a workbook with data and clear explanations of what you want and the expected result.

Thanks

Phil

Avatar
Arunachal Jois
Member
Members
Level 0
Forum Posts: 17
Member Since:
August 3, 2020
sp_UserOfflineSmall Offline
3
August 3, 2020 - 7:46 pm
sp_Permalink sp_Print

I have some data in col Z. If i found "Error" in col Z then i want to do vlookup in AA. If there is no "Error" in col Z then i dont want to Vlookup it in column AA.

Now i'm stuck in the below code

If WorksheetFunction.CountIf(Range("Z:Z"), "Error") > 0 Then
With Sheets("PIR Template")
With .Range("A1:AH1")
.AutoFilter
.AutoFilter Field:=26, Criteria1:="Error"
End With

Range("AA" & cell.Row).Select.Formula = "=VLOOKUP(RC[-2],ZLOE019!C1:C7,7,0)"

End With

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
August 3, 2020 - 10:04 pm
sp_Permalink sp_Print

Philip Treacy said

Please supply a workbook with data and clear explanations of what you want and the expected result.

Thanks

Phil  

I can't help without your workbook.

How exactly are you stuck?

Avatar
Arunachal Jois
Member
Members
Level 0
Forum Posts: 17
Member Since:
August 3, 2020
sp_UserOfflineSmall Offline
5
August 3, 2020 - 10:54 pm
sp_Permalink sp_Print sp_EditHistory

i will provide you the workbook with macro file

Simply saying i want to Vlookup a filtered data only for visible cell

I provided the information in Macro file and i also facing my macro button "Validation" not working properly
Could you please help on that also ? 

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
6
August 5, 2020 - 9:36 am
sp_Permalink sp_Print

Hi,

When the Validation sub runs you have these 3 lines of code at the top

   LR = Range("U" & Rows.Count).End(xlUp).Row
   LR1 = Range("B" & Rows.Count).End(xlUp).Row
   LR2 = Range("B" & Rows.Count).End(xlUp).Row

But these are acting on the active sheet which is FORM therefore they are all set to 1.

LR1 and LR2 are set to correct values later in your code, after you switch to other sheets.  But LR is not set to any other value so the code that relies on it is not working properly.

At the top of the validation sub, activate the sheet you want before setting values for LR, LR1 and LR2.

Regards

Phil

Avatar
Arunachal Jois
Member
Members
Level 0
Forum Posts: 17
Member Since:
August 3, 2020
sp_UserOfflineSmall Offline
7
August 5, 2020 - 5:20 pm
sp_Permalink sp_Print

Thanks for the solution
But i don't know how to do that
Can you make changes and send the revised file for me if possible ?

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
8
August 5, 2020 - 5:56 pm
sp_Permalink sp_Print sp_EditHistory

Hi,

I'm a bit confused.  I don't know what sheet you want the code to act upon.

All you need is a line like this

  Sheets("PIR Template").Activate

before the 3 lines that set values for LR, LR1 an LR2. 

I'm guessing that's the sheet you want but as I said, I don't know for sure.  How can I know? You need to tell me what sheet you want the code to work with.

Regards

Phil

Avatar
Arunachal Jois
Member
Members
Level 0
Forum Posts: 17
Member Since:
August 3, 2020
sp_UserOfflineSmall Offline
9
August 5, 2020 - 6:24 pm
sp_Permalink sp_Print

did you tried to run macro like that ?
Is it working fine ?

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
10
August 5, 2020 - 7:22 pm
sp_Permalink sp_Print

Seems to be, but again, you haven't clearly explained the problem or desired result to I'm guessing.  Have you tried it?

Avatar
Arunachal Jois
Member
Members
Level 0
Forum Posts: 17
Member Since:
August 3, 2020
sp_UserOfflineSmall Offline
11
August 5, 2020 - 8:16 pm
sp_Permalink sp_Print

Yes i tried it
Now it is working fine for me
Thanks for the support
I have one more question - in last i put VLookup
But i need vlookup for visible cells only. Can you please tell me to put Vlookup for visible cells only in col AA

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
12
August 5, 2020 - 8:24 pm
sp_Permalink sp_Print

The code does enter a VLOOKUP only for visible cells in AA.

If you are getting some other result please attach the workbook again so I can see what's happening.

Avatar
Arunachal Jois
Member
Members
Level 0
Forum Posts: 17
Member Since:
August 3, 2020
sp_UserOfflineSmall Offline
13
August 5, 2020 - 8:45 pm
sp_Permalink sp_Print

Okay will finish all the code today or tomorrow 
If any issues will contact you here again
Thank you so much again for your support Philip

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
14
August 5, 2020 - 10:37 pm
sp_Permalink sp_Print

You're welcome

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
Hans Hallebeek: 186
Newest Members:
Kate Dyka
Kwaje Alfred Mogga
thong nguyen
Appiagyei Kofi Frimpong
Hilary Burchfield
Richie Wright
Adel Kock
Barbara Murray
Doug Milne
Siobhan Stringer
Forum Stats:
Groups: 3
Forums: 24
Topics: 6546
Posts: 28658

 

Member Stats:
Guest Posters: 49
Members: 32832
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.