There is quite a popular question on avoiding select in Excel VBA, but that does not always seem to work, as you can see from this example:
There is a question about somebody, trying to find something on an Excel sheet, so I decided to help.
First I selected some cells and launched a Find
, everything was working fine, so I recorded this as a VBA macro:
Range("B1:B10").Select
Selection.Find(What:="test", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Then, as usual, I removed the Select
, turning my macro into this:
Range("B1:B10").Find(What:="test", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
To my surprise, this yielded a Type Mismatch
error.
Why is that?
And what about avoiding the "Select" in VBA? Are there more such cases where this is not possible?