Using VLOOKUP in VBA
Hi Chad:
Vlookup needs the key to be on the left of the data.
As is:
'assume that DueDate is already a valid value
dim WS as worksheet
dim v as variant
set WS =activesheet
v = Application.WorksheetFunction.VLookup( _
DueDate, WS.range("G1:K500"), 5, True)
In your case:
dim WS as worksheet
dim v as variant
set WS =activesheet
v = Application.WorksheetFunction.Match( _
DueDate, WS.range("G1:G500"), 1)
if isna(v) then
msgbox "cannot match",vbokonly,"error"
exit sub
end if
v=WS.cells(v, 5)
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.
" wrote:
Just need a quick clarification; I am trying to find a value (Job
Number) in the same row as the DueDate variable shown in the procedure
below. I can't get it to work, I was assuming it would find the
closest date if there were no matches. Is this correct?
dim rngdate as range
dim WS as worksheet
rngDate = WS.Application.WorksheetFunction.VLookup(DueDate, "G1:G500",
5, True)
I would like to search through column G for the DueDate, and return
the corresponding Job Number in column 5.
Thanks for any help,
Chad
|