Populate Listbox with values from Combobox Selection

Tmarques

New Member
Joined
Mar 29, 2017
Messages
1
Hi all

Wondering if someone could help with the following issue.
I have a userform that is used to populate values to a sheet.
This uses a preliminary selection from a ComboBox value and its supposed to show on a ListBox the values categorized with the text coming from the ComboBox.
The values are available in a regular excel sheet:

jupejp00118.-
jupejp00226.-
Pantalonpt00116.-
Manteauxmt00120.-
Manteauxmt00231.-

<tbody>
</tbody>

Hence, whenever in the Combobox I select a column A value the Listbox will show the values from columns B and C.

I've managed to get the ListBox to show only values from the column A selection, albeit for multiple instances I only have the first instance found showing.
My idea would be to make a loop that would run for each single instance where the values in column A are found and add the values from columns B to C to the listbox

Below follows the code so far:

Code:
Private Sub UserForm_Initialize()
Facture.Activate
TextBox1 = "1"


Dim Prix As Worksheet
Set ws = ThisWorkbook.Sheets("Prix")

'creation of an array to populate the combobox with single values by removing duplicates


wsLR = ws.Cells(Rows.Count, 1).End(xlUp).Row
firstTime = True


For x = 2 To wsLR
    If ws.Cells(x, 1) <> "" And (InStr(unik, "|" & ws.Cells(x, 1) & "|") = 0) Then
        If firstime = True Then
            unik = "|" & unik & ws.Cells(x, 1) & "|"
        firstTime = False
        Else
            unik = unik & "|" & ws.Cells(x, 1) & "|"
        End If
    End If
    
 Next x

'add values to combobox


myArray = Split(unik, "|")
ComboBox1.Clear


For Each Cell In myArray
    If Cell <> "" Then
        ComboBox1.AddItem Cell
    End If
Next Cell


End Sub



Private Sub ComboBox1_Change()


    Dim searchResult As Range
    Dim rngToFind As Range
    Dim valToFind As Variant
    Dim arrClearList()

'search for values based on the combobox selection
    
    valToFind = ComboBox1.Value
        With Worksheets("Prix")
        Set searchResult = .Columns("A")
    End With
            Set rngToFind = searchResult.Find(What:=valToFind, _
                LookIn:=xlFormulas, _
                LookAt:=xlWhole, _
                SearchOrder:=xlByRows, _
                SearchDirection:=xlNext, _
                MatchCase:=False)
                  
        If Not rngToFind Is Nothing Then
            ListBox1.Clear

' add values to list__ This is where I have issues since I'm unable to develop a loop which would run the below script for all instances where the value of the combobox is found in the Worksheet.


            ListBox1.AddItem
            
        With ListBox1
            .List(.ListCount - 1, 0) = rngToFind.Offset(0, 1).Value
            .List(.ListCount - 1, 1) = rngToFind.Offset(0, 2).Value
            .List(.ListCount - 1, 2) = rngToFind.Offset(0, 3).Value
        
        End With
        End If
        
End Sub

Thanks in advance for the support.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,822
Messages
6,121,772
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top