# VLOOKUP over multiple sheets

#### Yusuf

##### Active Member
Hi
Is it possible to write a VLOOKUP formula that searches for a result over multiple sheets in the same workbook?

### Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use \$ signs: \$V\$2:\$Z\$99 will always point to V2:Z99, even after copying

#### Jonmo1

##### MrExcel MVP
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``````

Replies
5
Views
252
Replies
9
Views
142
Replies
9
Views
291
Replies
4
Views
244
Replies
6
Views
274

1,181,418
Messages
5,929,796
Members
436,695
Latest member
yashpisat

### 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.

### Which adblocker are you using?

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

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