View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Roger Govier[_3_] Roger Govier[_3_] is offline
external usenet poster
 
Posts: 2,480
Default Searching specific record using VLOOKUP function.

Hi

Regrettably there is no way to tell Vlookup to start from the end and work
upwards.
If you can accept a VBA solution, the following code will do what you want
(no error checking built in)
It assumes your codes are in column A and Values in column B

Sub FindLast()
Dim rng As Range, code As String, lr As Long, value As Double
lr = Cells(Rows.Count, "A").End(xlUp).Row
code = InputBox("Enter Code to find.")
Set rng = Nothing
Set rng = Range("A1:A" & lr).Find(what:=code, _
After:=Range("A" & lr), _
LookIn:=xlFormulas, _
lookat:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
value = rng.Offset(0, 1).value
MsgBox code & " has a value of " & value
End Sub

Copy the Code above
Alt+F11 to invoke the VB Editor
InsertModule
Paste code into white pane that appears
Alt+F11 to return to Excel

To use
Select sheet containing the PT's
Alt+F8 to bring up Macros
Highlight FindLast
Run

Alternatively you could add a button to your sheet and assign the macro to
it.
--
Regards
Roger Govier

"dev" wrote in message
...
My table is not sorted and it has multiple entries for a search criteria.
I
want last entry to be picked up by vlookup. Is there any way to do that?
Or
can vlookup search from the bottom of the table? This will also solve my
problem.
e.g.
Item Price
it1
it2 32
it3
it1
it4 44
it1 11
it3 20

So, there can be multiple entries for an item but only one entry will have
Price (Price will be blank for all other entries of that item). This entry
will be the last occurrence of that item in the table. I want price of
that
occurrence.