Question on vba that i found for doing a vlookup across multiple sheets

rogeryung

New Member
Joined
Mar 10, 2010
Messages
33
Hi, I'm trying to do a vlookup across multiple sheets and found the macro listed at the bottom. It works, but it's doing a lookup across all sheets. Can anyone tell me how to change it so that it only looks at a specific set of sheets? Basically I want it to look at all sheets between a sheet called "Start" and a sheet called "End"

Thank you

Here it is:

Function VLOOKAllSheets(Look_Value As Variant, Tble_Array As Range, Col_num As Integer, Optional Range_look As Boolean)








Dim wSheet As Worksheet


Dim vFound






On Error Resume Next






For Each wSheet In ActiveWorkbook.Worksheets


With wSheet


Set Tble_Array = .Range(Tble_Array.Address)


vFound = WorksheetFunction.VLookup _
(Look_Value, Tble_Array, _
Col_num, Range_look)


End With


If Not IsEmpty(vFound) Then Exit For


Next wSheet






Set Tble_Array = Nothing


VLOOKAllSheets = vFound


End Function
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try
Code:
Function VLOOKAllSheets(Look_Value As Variant, Tble_Array As Range, Col_num As Integer, Optional Range_look As Boolean)
Dim wSheet As Worksheet, i As Long, vFound
On Error Resume Next
For i = Sheets("Start").Index To Sheets("End").Index
    Set wSheet = Sheets(i)
    With wSheet
        Set Tble_Array = .Range(Tble_Array.Address)
        vFound = WorksheetFunction.VLookup _
        (Look_Value, Tble_Array, _
        Col_num, Range_look)
    End With
    If Not IsEmpty(vFound) Then Exit For
Next i
Set Tble_Array = Nothing
VLOOKAllSheets = vFound
End Function
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,842
Members
449,193
Latest member
MikeVol

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