type mismatch on find function

  • Thread starter Thread starter Scooter
  • Start date Start date
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
 
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"
 
The "After" argument needs to be an actual Range value, not a String value.
Use this for it...

After:=Range("A44")
 
Dim rResult As Range
SET rResult = Range("a:a").Find(What:="abc", After:=Range("A44")
 
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).
 
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.
 
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")
 
Back
Top