VLOOKUP over multiple sheets

Yusuf

Active Member
Joined
Jun 1, 2004
Messages
337
Hi
Is it possible to write a VLOOKUP formula that searches for a result over multiple sheets in the same workbook?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I've been working on that...

This UDF is probably extremely ineficient, but it works so far...
You only have to use 2 areguments in this function. But there are 3 optional arguments.
Code:
=myvlookup(lookupvalue,range,"sheetname","sheetname","sheetname")
the 3 sheetnames are optional, if omitted, it searches the sheet the function is entered on.

I've only written it for 3 sheets so far. You can add to it if you like.

I purposely left out the ColumnIndex in my vlookup. it will default to the # of columns in the range you specify. so if you look in A:C - it will be 3.

Code:
Public Function myvlookup(myvalue As String, myrange As Range, Optional a As String, Optional b As String, Optional c As String)
Dim myarray()
x = myrange.Column
Y = x + myrange.Columns.Count - 1


sarray = Array(a, b, c)
For i = 0 To WorksheetFunction.CountA(sarray) - 1
    If sarray(i) <> "" Then Count = Count + 1
Next i
Count = Count - 1

If Count < 0 Then
    Count = 0
    sarray = Array(myrange.Parent.Name)
End If

For i = 0 To Count
    LR = LR + Sheets(sarray(i)).Cells(Rows.Count, x).End(xlUp).Row
Next i

ReDim myarray(2, LR)


For i = 0 To Count
    LR = Sheets(sarray(i)).Cells(Rows.Count, x).End(xlUp).Row
    For j = 1 To LR
        myarray(0, j + RowCount) = Sheets(sarray(i)).Cells(j, x).Value
        myarray(1, j + RowCount) = Sheets(sarray(i)).Cells(j, Y).Value
    Next j
    RowCount = RowCount + LR
Next i

For Z = 0 To RowCount
    With WorksheetFunction
    If .Proper(myarray(0, Z)) = .Proper(myvalue) Then q = myarray(1, Z)
    End With
Next Z

myvlookup = q
End Function
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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