I have the below code which finds text based on what is in cell D1. I have a button connected to this code but what i want to happen is when the user presses the button once its finds the first instance, then if the press again it goes to the 2nd and so on down. Currently it just finds the first instance and nothing else.
I get that you can just use CTRL + F for the same thing but there is a reason I want it to be coded, thanks in advance
Sub search()
Dim FindString As String
Dim Rng As Range
FindString = Range("D1")
If Trim(FindString) <> "" Then
With Sheets("Data").Range("B:B")
Set Rng = .Find(what:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.GoTo Rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
End Sub
I get that you can just use CTRL + F for the same thing but there is a reason I want it to be coded, thanks in advance
Sub search()
Dim FindString As String
Dim Rng As Range
FindString = Range("D1")
If Trim(FindString) <> "" Then
With Sheets("Data").Range("B:B")
Set Rng = .Find(what:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.GoTo Rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
End Sub