Normally you use the VLOOKUP function to find things in a table or a range by row. E.g., look up a price of a mower part by the part number The function works fine for a specific table in a given worksheet.
But, let's say, you have a workbook with related several tables located in different worksheets. You might need to check all worksheets to find a match for your lookup value. In such a case you would need to use the VLOOKUP repeatedly in each of the worksheets. Much more efficient would be using this UDF (User Defined Function) I've created to make the task easier:
Function VLOOKUPinWBK(lookup_value As Variant, table_array As Range, _
col_index_num As Integer, Optional range_lookup As Boolean)
'This UDF looks in ALL worksheets in your workbook and finds the
' first match for lookup_value.
Dim wSh As Worksheet
Dim wks As String
Dim vLooked
On Error Resume Next
For Each wSh In ActiveWorkbook.Worksheets
With wSh
wks = wSh.Name
Set table_array = .Range(table_array.Address)
vLooked = WorksheetFunction.VLookup(lookup_value, table_array, _
col_index_num, range_lookup)
End With
If Not IsEmpty(vLooked) Then vLooked = vLooked: Exit For
Next wSh
Set table_array = Nothing
VLOOKUPinWBK = vLooked & " (found in '" & wks & "')"
End Function