type mismatch on find function

S

Scooter

I am getting a type mismatch on this

Dim intResult As Integer
intResult = Range("a:a").Find(What:="abc", After:="A44", LookIn:=xlValues,_
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext,_
MatchCase:=False, SearchFormat:=False).Row

I have also tried
intResult = Cells.Find(What:="abc", After:="A44", ...).Row
intResult = Selection.Find(What:="abc", After:="A44", ...).Row
 
S

Scooter

I get a "compile error: type mismatch" with your suggestion. If I take the
".row" off the end of the Find, I still get the "run time error 13: type
mismatch"
 
R

Rick Rothstein

The "After" argument needs to be an actual Range value, not a String value.
Use this for it...

After:=Range("A44")
 
P

Patrick Molloy

Dim rResult As Range
SET rResult = Range("a:a").Find(What:="abc", After:=Range("A44")
 
R

Rick Rothstein

There is no need for the OP to do this given what the statement does. Look
at the .Row property call at the end of his Find function call... he is
picking off the Row from the cell that was found by the Find function. Of
course, doing it this way will require the OP to have some error checking
routine to trap the error that will be generated if the text he is searching
for doesn't appear anywhere in Column A (the range he is searching).
 
P

Patrick Molloy

i missed off the last closed bracket

SET rResult = Range("a:a").Find(What:="abc", After:=Range("A44") )

FIND returns a range object, hence the DIM as Range and we sue SET to assign
the found object to it.
 
S

Scooter

That did the trick. Thanks much.

Rick Rothstein said:
The "After" argument needs to be an actual Range value, not a String value.
Use this for it...

After:=Range("A44")
 

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

Top