VBA vlookup multiple sheets with multiple ifs

Sipirili2504

New Member
Joined
Aug 18, 2024
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hi. Appreciate it if you could advise me on how to convert this to VBA.
If column A2 contains apple, lookup in sheet appleweekly etc

=Vlookup(C2, IF(A2="APPLE", APPLEWEEKLY!A:Z, IF(A2="ORANGE", ORANGEWEEKLY! A:Z, IF(A2="LEMON", LEMONWEEKLY!A:Z))),5,0)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this:

VBA Code:
= Application.VLookup(Range("C2"), Sheets(Range("A2") & "WEEKLY").Range("A:Z"), 5, 0)
 
Upvote 0
Hi Phuoc. Thanks for the prompt response.

I have the below macro. It does not seems to work.
I am getting an error at the formula itself.
To make things more clear, I need this formula to be in the Master sheet at column AD2 to last row.
If column A2 is apple in Master sheet, I need to do a vlookup and see if the data in column C2 exist in the Appleweekly sheet and return data from column 5 to Master sheet column AD2.
If column A2 is orange, I need to do a vlookup and see if the data in column C2 exist in the Orangeweekly sheet and return data from column 5 to Master sheet column AD2.
Appreciate any help.

Dim RC as integer
RC = Range("A" & Rows.Count).End(xlUp).row

Range ("AD2").formula = "= Application.VLookup(Range("C2"), Sheets(Range("A2") & "WEEKLY").Range("A:Z"), 5, 0)
Range("AD2").Copy
Range("AD2:AD" & RC.pastespecialxlpasteall
Application.Cutcopymode= false
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top