Lookup Function

RWinfield

New Member
Joined
Feb 16, 2002
Messages
33
Probably an easy one. I need to modify the following function to allow Excel to search multiple worksheets for a value. Example...below lookup will look in the sheet "Finished Goods Inventory" for a value. This function works perfectly.

I would like to have it look in sheets "Finished Goods Inventory" and "Raw Inventory" both for the same value. Both the sheets mentioned are in the same workbook. I think this is possible, but I am not sure. Thanks in adavance for any help.

Rick

Function DoLookup(ID As String, strDesc As String, curPrice As Currency, lQty As Long, nRow As Long)
'After barcode is scanned do the lookup
Dim nLastRow As Long

'get last row containing data
nLastRow = Sheets("Finished Goods Inventory").Cells(65000, 1).End(xlUp).Row

With Worksheets(1)
Set c = .Range("a2:a" & Format$(nLastRow)).Find(ID, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
If c Is Nothing Then
DoLookup = False
nRow = 0
Exit Function
Else
nRow = c.Row
Rows(nRow).Select
strDesc = c.Offset(0, 1).Value
curPrice = c.Offset(0, 2).Value
lQty = c.Offset(0, 3).Value
DoLookup = True
End If
End With

End Function
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try (Untested)

<pre/>
Function DoLookup(ID As String, strDesc As String, curPrice As Currency, lQty As Long, nRow As Long)
'After barcode is scanned do the lookup
Dim nLastRow As Long
Dim c
Dim Sh As Worksheet '<<

For Each Sh In ThisWorkbook.Sheets '<<
If Sh.Name = "Finished Goods Inventory" Or Sh.Name = "Finished Goods Inventory" Then

'get last row containing data
nLastRow = Sheets("Finished Goods Inventory").Cells(65000, 1).End(xlUp).Row

With Sh
Set c = .Range("a2:a" & Format$(nLastRow)).Find(ID, LookIn:=xlValues, _
lookat:=xlWhole, MatchCase:=True)
If c Is Nothing Then
DoLookup = False
nRow = 0
Exit Function
Else
nRow = c.Row
Rows(nRow).Select
strDesc = c.Offset(0, 1).Value
curPrice = c.Offset(0, 2).Value
lQty = c.Offset(0, 3).Value
DoLookup = True
End If
End With
End If
Next
End Function

</pre>
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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