Results 1 to 9 of 9

Thread: how to loop search to show multiple entries in listbox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    5
    Location

    how to loop search to show multiple entries in listbox

    I need help with my code, im trying to create a searchable database using a userform. I would like to have a text box were a part number can be entered and then clicking a search button would perform a search in the tab “database” this tab holds all inventory details such as part number, description,qty,location ect. I have the below code that is working to return the correct information to the listbox based on the text box value, but the problem im having is setting it up to loop and return all entries in sheet “database” that match the value of the text box. Can you guys please help to get a loop in here and return all appropriate matches? Screen shoot below as well for reference. Also i would like once the records are returned to the listbox the user has the option to double click a line within the list box and have the corresponding information displayed in the textboxs above.

    LISTBOX.jpg

    Private Sub parts2_Click()
     Dim rngToSearch As Range
        Dim rngToFind As Range
        Dim valToFind As Variant
        Dim arrClearList()
    
        valToFind = partsearch2.Value 'ComboBox name
        With Worksheets("database")
            Set rngToSearch = .Columns("A")
        End With
    
        Set rngToFind = rngToSearch.Find(What:=valToFind, _
                LookIn:=xlFormulas, _
                LookAt:=xlWhole, _
                SearchOrder:=xlByRows, _
                SearchDirection:=xlNext, _
                MatchCase:=False)
    
        If Not rngToFind Is Nothing Then
            ListBox2.AddItem
            With ListBox2
                .List(.ListCount - 1, 0) = rngToFind.Value  'part number
                .List(.ListCount - 1, 1) = rngToFind.Offset(0, 1).Value 'desc
                .List(.ListCount - 1, 2) = rngToFind.Offset(0, 2).Value 'stor loc
                .List(.ListCount - 1, 3) = rngToFind.Offset(0, 3).Value 'bin loc
                .List(.ListCount - 1, 4) = rngToFind.Offset(0, 4).Value 'qty
                .List(.ListCount - 1, 5) = rngToFind.Offset(0, 5).Value 'mfg
                .List(.ListCount - 1, 6) = rngToFind.Offset(0, 7).Value 'pm name
            End With
    
        Else
            MsgBox valToFind & " Not found in Database."
        End If
    End Sub
    Last edited by SamT; 01-26-2018 at 01:16 PM. Reason: Added Code Formatting Tags via # Icon

Tags for this Thread

Posting Permissions

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