Unable to get the VLookup property of the WorksheetFunction class
Do you really want to do any comparisons to " "? Your =vlookup() could return a
single space character?
========
I'd use:
dim Res as variant 'could be an error
res = application.vlookup(location, sheets("City").range("a2:b3", 2, false)
with Worksheets("Master")
if iserror(res) then
.range("V3").value = "Missing"
else
.range("V3").value = res
end if
end with
==========
Saved from a previous post:
There is a difference in the way application.vlookup() and
worksheetfunction.vlookup() (or application.worksheetfunction.vlookup()) behave.
Application.vlookup returns an error that you can check:
dim Res as variant 'could return an error
res = application.vlookup(....)
if iserror(res) then
msgbox "no match"
else
msgbox res
end if
Application.worksheetfunction.vlookup raises a trappable error that you have to
catch:
dim res as variant
on error resume next
res = application.worksheetfunction.vlookup(...)
if err.number < 0 then
msgbox "no match"
else
msgbox res
end if
on error goto 0
(application.match() and application.worksheetfunction.match() behave the same
way.)
Personally, I find using the application.vlookup() syntax easier to read. But
it's personal preference.
Ayo wrote:
How do I go around this runtime error? I tried the following:
If Application.WorksheetFunction.VLookup(c.Offset(0, 2).Value,
rngsStatusdata, 7, False) < " " Then
If Application.WorksheetFunction.VLookup(c.Offset(0, 2).Value,
rngsStatusdata, 7, False) < "#N/A" Then
If Application.WorksheetFunction.VLookup(c.Offset(0, 2).Value,
rngsStatusdata, 7, False) < "#N/A" Then
trueOnAirWS.Range("J" & reportCurrentRow & "") =
Application.WorksheetFunction.VLookup(c.Offset(0, 2).Value, rngsStatusdata,
7, False)
End If
--
Dave Peterson
|