VLOOKUP across multiple sheets

dhatkoff

New Member
Joined
Aug 17, 2005
Messages
5
Hello all,

I've got a workbook that has roughly 60 sheets, with ID numbers in column A on every sheet. I am trying to write a public function in VBA that will essentially extend the VLOOKUP function so that it will return the first value that corresponds to the lookup value in whatever sheet has the ID number. Here is the code I have so far:

Public Function supervlookup(refrange As Range, rangename As Range, columnnumber As Integer)

Dim sh As Worksheet

For Each sh In Worksheets

If Not Application.WorksheetFunction.IsErr(Application.WorksheetFunction.VLookup(refrange, rangename, columnnumber, "false")) Then
supervlookup = Application.WorksheetFunction.VLookup(refrange, rangename, columnnumber, "false")
Exit Function
Else

End If
Next sh

End Function




The function thusfar works if the ID being searched for is on the same page as the formula, but it returns a #NUM error if the ID is on another sheet. Any help would be greatly appreciated!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,203,436
Messages
6,055,372
Members
444,781
Latest member
rishivar

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