Years ago I was asked, if it is possible to search with two search criterias in worksheet. So, I want to search both A and B whichever I find first. Normally you search in Excel with just one criteria like this:

To find take home-find & select – find.

First search for A.

Then search for B.
If you however want to search for both A and B at the same go, then we need some further development.
Here is the VBA code from a recorded macro searching for A.
Sub Z_search()
‘
‘ Z_search Macro
‘
‘
Cells.Find(What:=”A”, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
End Sub
To modify the VBA, first the main block should be doubled that first the search term 1 is searched and the search term 2. Static “A” should be replaced by parameter. The main block is copied from recorded macro.
On Error Resume Next means that if VBA hits an error, the code is not stopped there. This is needed because if the macro does not find anything, it will face a run time error 91. With this line the VBA does not stop with run time error.
Here is the code
Sub z_search()
‘
‘ z_search Macro
‘
Dim s1, s2
s1 = InputBox(“1st search term”)
s2 = InputBox(“2nd search term”)
On Error Resume Next
‘ this part was recorded and then what-parameter was modified, I did not write this myself
Cells.Find(What:=s1, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
Cells.Find(What:=s2, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
End Sub
If the code find both the first term and the second term, then the program is showing the place of the second term, but this is a functionality.























