Lookup "Next" function in VBA

Rashie

Board Regular
Joined
Jun 5, 2015
Messages
55
Hey All,

I'm trying to make something to help my team.
I'm using a vlookup function and it's working great like it always does BUT some values I use to lookup have multiple results (i.e. 2 or 3.) 90% of my values are unique.

I'm looking for a way to either have a VBA button that says "Next" and displays the next result the lookup can find, or have multiple results from the same data (i.e. Possible option 1, possible option 2, possible option 3.)

Price
8821.90 - This is my value I'm using to search
Name:XXX (=VLOOKUP(B2,USDREP!A:T,2,FALSE)
TypeXXX (=VLOOKUP(B2,USDREP!A:T,3,FALSE)
AccessOnline-only(=VLOOKUP(B2,USDREP!A:T,8,FALSE)
Price CodeINSTIT (=VLOOKUP(B2,USDREP!A:T,13,FALSE))
Item NumberXXX (=VLOOKUP(B2,USDREP!A:T,14,FALSE)

<tbody>
</tbody>


Can anybody suggest a way to have multiple lookups? To confirm, Value 8821.90 may have 2 seperate unrelated results, XXX & YYY.

Thanks for your help,

Rashie.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
It works in the following way:
- Create a button on your sheet.
- Assign the macro to the button.
- Put the price in cell B2.
- Press the button.


- Press the button to go to the next record.

Note: The macro requires an auxiliary cell to take control of the next record, cell D1, you can change it for the one you want.


c5c56958ab2575e2febde99e30026bb3.jpg



Code:
Sub lookup_Next()
    Dim sh1 As Worksheet, sh2 As Worksheet, f As Range, i As Long, aux As Range
    Set sh1 = ActiveSheet
    Set sh2 = Sheets("USDREP")
    Set aux = sh1.Range("[COLOR=#ff0000]D1[/COLOR]")   'Auxiliary cell
    If aux.Value = "" Then i = 1 Else i = aux.Value
    Set f = sh2.Range("A:A").Find(sh1.Range("B2").Value, after:=sh2.Range("A" & i), LookIn:=xlValues, lookat:=xlWhole)
    sh1.Range("B4").Value = sh2.Cells(f.Row, 2).Value
    sh1.Range("B5").Value = sh2.Cells(f.Row, 3).Value
    sh1.Range("B6").Value = sh2.Cells(f.Row, 8).Value
    sh1.Range("B7").Value = sh2.Cells(f.Row, 13).Value
    sh1.Range("B8").Value = sh2.Cells(f.Row, 14).Value
    aux.Value = f.Row
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
Members
448,973
Latest member
ChristineC

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