Error 2042

  • Thread starter Thread starter papa jonah
  • Start date Start date
P

papa jonah

I am trying to use the match function within vba without using a cell.
The following is how I was told to do it. I am trying to match the
value of begbase (which is "10/1/97" in this case).

Dim sb As Variant

sb = Application.Match(begbase, Range("a2:a" & causerows))

What I get is Error 2042. I don't know what that is. Can some one
either tell me what it is, or better yet, how to solve the problem?

TIA
 
Error 2042 means that the Match was not found. It's equivalent to
returning #N/A when called from the worksheet.

Since you're not using the match type argument, it means a value greater
than sb was found before sb, if sb exists in the target range.
 
Are you trying to find an exact match?

If yes:

dim SB as variant
sb = application.match(begbase,range("a2:a" & causerows),0))
if iserror(sb) then
'not found
else
'found
end if

Sometimes with dates, this works better:
sb = application.match(clng(begbase),range("a2:a" & causerows),0))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top