PDA

View Full Version : Find function



Bishop
08-17-2016, 04:15 AM
Hi all !

I guess it should be quick : I am looking for tips to handle the "Find" function and especially the "What" part.
Most forums I have been on present the function this way :

Cells.Find(What:="Cat", After:=ActiveCell, LookIn:=xlValues, LookAt:= _

xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _

, SearchFormat:=False).Activate

In my code, I would like to replace "Cat" by the value of a cell. I have tried : Range("A1").Value , "Range("A1").Value" and even using an intermediate string to host the value but it is still bugging.

Thanks to any help guys :)

Jan Karel Pieterse
08-17-2016, 04:36 AM
The Range("A1").Value should work:


Cells.Find(What:=Range("A1").Value, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate

Paul_Hossler
08-17-2016, 06:15 AM
Try being explicit with Cells and Range and see if that helps




Activesheet.Cells.Find(What:=Activesheet.Range("A1").Value, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate



JKP is correct (as always) that Range("A1").Value should work. but check that there are no leading or trailing spaces in A1: "cat" <> "cat "