View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Vlookup macro run time error

It sounds like the =vlookup() is returning an error.

if iserror(readerresult) then
msgbox "no match found"
else
msgbox readerresult
end if

may help your debugging.

You may want to post the formula that worked in the cell.

And what is contained in the variables in that line of code.



Daveh wrote:

Dave

earlier optimism unfounded !! The code line now works (berfore it was
failing) but I cannot use the vlookup response.

I am expecting a "yes" or "no" result from vlookup in my "readerresult"
variable but subsequent macro commands do not like whatever the contents of
"readerresult" is.

I have tried the vlookup function with my data in a spreadsheet and it does
what I expect but not when I try to code it in a macro.

"Dave Peterson" wrote:

Try dropping the .worksheetfunction. from the line:

dim ReaderResult as Variant 'note that it's a variant

readerresult = application.vlookup(....)
if iserror(readerresult) then
'it wasn't found
else
'it was found
end if

If you use the .worksheetfunction stuff, you'll have to trap for the error.

dim ReaderResult as String 'long, whatever

on error resume next
readerresult = application.worksheetfunction.vlookup(....)
if err.number < 0 then
err.clear
'not found
else
'found
end if
on error goto 0

I find the first method easier to use.


Daveh wrote:

I get Run time error 1004 Unable to get the Vlookup property of the worksheet
function class as an error message when i run the following macro command

Readerresult = application.worksheetfunction.vlookup(userselectio n,
classlistrange,2)

Excel 2000.

Hope you can help !


--

Dave Peterson


--

Dave Peterson