Find function in VBA acts strangely (excel)

musicgold

New member
Local time
Today, 07:04
Joined
Dec 7, 2009
Messages
6
Hi,

I am trying to search a word in the activesheet using the following code. VBA is behaving strangely, in that, when I run the macro it is not able to find the word, even though the word is there in the worksheet. However, when I step through the macro (using F8) the Find function is able to find the word.
I am not sure what is going on here.

Code:
[FONT=Arial]…[/FONT]
[FONT=Arial]ActiveSheet.UsedRange.Select[/FONT]
[FONT=Arial]Srch = "Net Absorption"[/FONT]
 
[FONT=Arial]Selection.Find(What:=Srch, After:=ActiveCell, LookIn:=xlValues, _[/FONT]
[FONT=Arial]LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _[/FONT]
[FONT=Arial]MatchCase:=False).Activate[/FONT]

Thanks.
 
Not sure what you are trying to do with the code but it finds it fine for me. As the code is written it highlights the whole worksheet with the cell with Net Absorption being clear, I changed the activate to Select and added msgbox Selection.Address and the cell was selected and its address shown in the msgbox.

Brian
 

Users who are viewing this thread

Back
Top Bottom