• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

"Find Next" code

Artisez

Member
I am using the following code for a command button to find text in a text box. Is there a code or an edit to the next text? I use a spreadsheet that may have a word listed multiple times. The current code stops at the first text found, I need a way to go to the next text.

Code:
Private Sub CommandButton2_Click()
Dim ws As Worksheet
    Dim FindString As String
    Dim Rng As Range

    Set ws = ThisWorkbook.Worksheets("Data")

    FindString = TextBox1.Value

    If Trim(FindString) <> "" Then
        Set Rng = ws.Cells.Find( _
                         What:=FindString, _
                         LookIn:=xlValues, _
                         LookAt:=xlPart, _
                         SearchOrder:=xlByRows, _
                         SearchDirection:=xlNext, _
                         MatchCase:=False, _
                         SearchFormat:=False)

        If Not Rng Is Nothing Then
            Application.Goto Rng, True
        Else
            MsgBox "Nothing found"
        End If
    End If
End Sub


Any help would be greatly appreciated
 
Well I cannot get any to work. I am using a text box for typing in the search and then a command button to initiate the search. I was just trying to find a way to incorporate a "Find Next" method for the next word with the same wording.

I had previously found the above links and tried them before posting here and as well tried after it was posted. Unfortunately I am not an expert at this.
 
With the code I use now it will find the first match then stop. But as indicated in the example I sometimes have to do a search by, for example a company. Trying to set it up to find the next match.
 

Attachments

  • Example.JPG
    Example.JPG
    36 KB · Views: 15
Artisez

Firstly, The contributors here, including myself, donate our time here,
We do not get paid or receive any remuneration

So when we ask for a Sample File, we want the data, not a picture of the data.

Why, because often our problems lie with the data, not the code, but secondly, is that we now have to waste time setting up some data that may or maynot be indicative of your problem.

This is time that could be used on another persons problem

In regards to your problem, please see the sample file attached
 

Attachments

  • Find Next.xlsm
    17.6 KB · Views: 9
I did not mean to trouble anyone and I apologize for any inconvenience. I will seek help else where. I appreciate the time once again my apologies.
 
My previous post has the answer you are seeking

I am not trying to chase you away, that isn't the idea, however it is important to point out issues.
People like Narayan and myself will read 20 to 30 posts a day and answer 10 to 20 posts per day.
Having to type data in and make assumptions about the state of this data, ie is this Field Numeric or Text takes time and if we get those assumptions wrong it can affect the solution.
I feel it is important to point this out to users so that we all benefit in the future
 
Is there a way to do this without the message box? Just go to the next match? Also how do you stop once you find what you are searching for? It seems you have to keep clicking until the search cannot find any other matches.
 
See attached.
Repeated clicks of the button go to the next instance.
 

Attachments

  • Chandoo36002Find Next.xlsm
    23.1 KB · Views: 4
Back
Top