+ Reply to Thread
Results 1 to 12 of 12

Thread: 2 column listbox userform search

  1. #1
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    2 column listbox userform search

    Hi all. I have a question which might be a bit tricky or unfeasible. But anyway, here it goes:

    In my worksheet, I have a searchbox which reads "Please type claim name below". Then when the string is typed by the user and the user presses search, a search takes place. All the values are then returned into a listbox below (ListBox1). When a value from the listbox is selected, and the go button is pressed, the entire row which contains the string is selected. Unfortunately, many of the claim names are the same, so it would be impossible for a user to know which is the right string to select. Now, each claim name belongs to a particular claimant in another column. So there might be several claims that have the name of "Land", but the claimants, listed in the adjacent column, would be different.
    i.e.
    A B
    (Claimant) (Claim)
    John Doe Land
    Suzy Q Land
    Bob **** Loss of Use
    etc.

    My Question: Is there a way to have both adjacent columns appear in the listbox when the user makes a search. So if "Land" is returned, for example, the following would appear in the listbox:
    John Doe Land
    Suzy Q Land

    My code is below. Thanks for any help or ideas!

    Private Sub btnGoTo_Click()
    
        If IsNull(Me.ListBox1.Value) Then
            MsgBox "Please select an item from the list.", vbOKOnly
            Exit Sub
        End If
        Sheets("Master").Rows(Me.ListBox1.Column(1, Me.ListBox1.ListIndex)).Select
        Unload Me
    MovingClaim
    End Sub
    
    Private Sub btnSearch_Click()
    
        Dim rng As Range
        Dim intRow As Integer
        Dim start As Range
    
        If Me.TextBox1.Value = "" Then
            MsgBox "Type in something to search for"
            Exit Sub
        Else
            With Sheets("Helper")
                Set rng = Sheets("Master").UsedRange.Find(Me.TextBox1.Value)
                Set start = rng
                Do
                    intRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
                    .Cells(intRow, 1).Value = rng.Value
                    .Cells(intRow, 2).Value = rng.Row
                Set rng = Sheets("Master").UsedRange.FindNext(rng)
                Loop While Not rng Is Nothing And rng.Address <> start.Address
            End With
        End If
    
        Me.ListBox1.RowSource = "Helper!A2:B" & Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row
    
    End Sub
    
    
    
    Private Sub ListBox1_Click()
    
    End Sub
    
    Private Sub UserForm_Initialize()
    
        Sheets("Helper").Range("A2:B" & Sheets("Helper").Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
    
    End Sub
    Last edited by touchofknowledge; 12-08-2011 at 10:41 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    433

    Re: 2 column listbox userform search

    It would be better if you did upload the file.
    you can add another combo box to list the applicable Claimants

  3. #3
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: 2 column listbox userform search

    SAMPLEEXERCISE.XLS

    Hi There. File should be attached. This is not the file I'm using (since the claimants are all confidential), but something I threw together that should get the idea across. I would like the claimant name to show up along with the claim when I search.

    Thanks!

  4. #4
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: 2 column listbox userform search

    Okay, hopefully this attachment works!
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    Excel 2010
    Posts
    522

    Re: 2 column listbox userform search

    maybe 3-column listbox?
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: 2 column listbox userform search

    Okay, but how would I go about that?

  7. #7
    Valued Forum Contributor
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    Excel 2010
    Posts
    522

    Re: 2 column listbox userform search

    I'm sorry, but my attachment is lost. Can you attach your sample file again?

  8. #8
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: 2 column listbox userform search

    I'll try this upload again. The security system where I work is fairly intense so I'm not sure if it'll upload properly... our browsers aren't exactly up to dateAttachment 131762

  9. #9
    Valued Forum Contributor
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    Excel 2010
    Posts
    522

    Re: 2 column listbox userform search

    See the attached file (attempt #2)

  10. #10
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: 2 column listbox userform search

    Hmm. It doesn't seem to be there... and the file I attached is no longer working (I swear the link worked before, I guess the links are temporary)...

  11. #11
    Valued Forum Contributor
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    Excel 2010
    Posts
    522

    Re: 2 column listbox userform search

    I will try to attach a file again. Download immediately until it disappeared.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: 2 column listbox userform search

    That is brilliant. Thank you so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0