VLOOKUP using IF function and multiple sheets

eeyore89

New Member
Joined
Apr 13, 2012
Messages
2
Hi,

I'm writing a VBA code:

There are 10 members who are either Male or Female.
"Males" and "Females" are two different worksheets with data on them.

Dim ELT As Variant

'If "M" is on the sheet, refer to "Males" worksheet else "F" for "Females" worksheet.
If ActiveCell.Offset(0,2).Value = "M" Then ELT = "Males" Else ELT = "Females"

I want to use a VLookup function to obtain a value dependent on whether they are Male or Female and hence to know which worksheet to look through.

I have tried:

Sheets(ELT).Activate
Lx = WorksheetFunction.VLookup(Age, Range("A1:B200"), 2, False)

but it cannot locate the 2nd argument i.e. the sheet where the data needs to be obtained.

Any help would be greatly appreciated!

Many thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
if ELT="Males" then
Lx = WorksheetFunction.VLookup(Age, sheets("Males").Range("A1:B200"), 2, False)
else
Lx = WorksheetFunction.VLookup(Age, sheets("FeMales").Range("A1:B200"), 2,false)
end if
 
Upvote 0
Thank you so much!! :) I didn't think an IF statement would work properly whilst already within another IF statement and a FOR loop. Thanks once again! :)
 
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,458
Members
449,161
Latest member
NHOJ

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