Searching in Two Non-Continguous Columns
I would like to attach a button to a worksheet that executes a string search
in two non contiguous columns. Once an item is found, theoretically, the
search would continue after the active cell each time the button is pressed.
The code I wrote does this imperfectly. Each time the button is pressed, it
moves on to the next item found in the first of the two columns but will not
continue to find through the second column in the range (it stops at the
first cell in the second column and then returns to the first column and
continues the search). Is there a way to search through both columns?
Any help received would be most appreciated. Thank you.
Here is the code:
Dim SearchTarget As String
MyRow = Selection.Row
Range("G" & MyRow).Activate
Set Rng = Range("G:G,O:O") 'search columns G and O
With Rng
Set FoundCell = .Cells.Find(What:=SearchTarget, _
After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False)
End With
If FoundCell Is Nothing Then
MsgBox SearchTarget & " was not found."
Else
FoundCell.Activate
End If
|