hawksbowl2014
New Member
- Joined
- Feb 3, 2014
- Messages
- 22
Hello,
I have a Userform that has a Search box so a user can search for key words. While it does work and will select all relevant cells, one cannot cycle through the results like the built in FindNext funtion. I would like the 'NextResultButton' to progress the ActiveCell through the search results selected cells. Here is the current Search code (attempted Loop posted below) :
And here is what I was trying to use to be able to cycle through:
~ Thank you
I have a Userform that has a Search box so a user can search for key words. While it does work and will select all relevant cells, one cannot cycle through the results like the built in FindNext funtion. I would like the 'NextResultButton' to progress the ActiveCell through the search results selected cells. Here is the current Search code (attempted Loop posted below) :
Code:
Private Sub SearchButton_Click()
Dim fnd As String, FirstFound As String
Dim FoundCell As Range, rng As Range
Dim myRange As Range, LastCell As Range
Dim ws As Worksheet
fnd = (TextBox1.Value)
Set myRange = ActiveSheet.UsedRange
Set LastCell = myRange.Cells(myRange.Cells.Count)
Set FoundCell = myRange.Find(what:=fnd, after:=LastCell)
If Not FoundCell Is Nothing Then
FirstFound = FoundCell.Address
Else
GoTo NothingFound
End If
Set rng = FoundCell
Do Until FoundCell Is Nothing
Set FoundCell = myRange.FindNext(after:=FoundCell)
Set rng = Union(rng, FoundCell)
If FoundCell.Address = FirstFound Then Exit Do
Loop
rng.Select
Exit Sub
NothingFound:
MsgBox "No Matches were Found"
End Sub
And here is what I was trying to use to be able to cycle through:
Code:
Private Sub NextResultButton_Click()
With Worksheets(1).Range("a4:k500")
Set c = .Find("textbox1.value")
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = ActiveCell.Select
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub
~ Thank you