Consulting

Results 1 to 3 of 3

Thread: Find all instances of a word and return the results in a userfrom - not working

  1. #1

    Unhappy Find all instances of a word and return the results in a userfrom - not working

    Hi - I have the following code (the find part coming from the VBA help example for find method) but it's not working. Can anyone spot any obvious error's I've made??

    Also I think the VBA Find method may be case specific (I know it is is formula's in Excel) - if so is there an alternative method I can use to find all the instances of a word in a column, that would for exampe find instances of the word test that are entered as "test", "Test" or "TEST"?

    [vba]Private Sub CommandButton1_Click()
    Dim SearchText As String
    SearchText = "Test"

    ListBox1.Clear
    ListBox1.Visible = False

    With Worksheets("Find Text - Test").Range("D25000")
    Set c = .Find(SearchText, LookIn:=xlValues)
    If Not c Is Nothing Then
    FirstAddress = c.Address
    Do
    ListBox1.AddItem (c.Value)
    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> FirstAddress
    End If
    End With

    ListBox1.Visible = True

    End Sub[/vba]

    Thanks for looking.

    Cheers,
    rrenis

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not working, in what way?

    It works fine for me, finds Test and test, but the Listbox is a bit boring.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks xld - your reply got me looking at things outside the code. Column D is hidden and the sheet is protected - when I unprotected the sheet and had unhidden column D it worked fine!!

    Cheers,
    rrenis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •