Populate ActiveX Listbox from criteria

jbroge

New Member
Joined
Dec 12, 2018
Messages
2
Hi all. I'm trying to fill the list box (ActiveX) with names that have an active flag and skip names who don't have an active flag.

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Tom[/TD]
[TD]Active[/TD]
[/TR]
[TR]
[TD]Kenny[/TD]
[TD]Active[/TD]
[/TR]
[TR]
[TD]Carrie[/TD]
[TD]Not Active[/TD]
[/TR]
[TR]
[TD]Jane[/TD]
[TD]Active[/TD]
[/TR]
[TR]
[TD]Ed[/TD]
[TD]Not Active[/TD]
[/TR]
</tbody>[/TABLE]

I created an named range that refers to both columns and entered it into the "ListFillRange" in the properties window and set "ColumnCount" to 2. This shows both columns inside the list box, but I don't know what to do next to only show those who are "Active".

Thanks in advance!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
First, clear the ListFillRange property. Then try the following code...

Code:
    Dim lbx As MSForms.ListBox
    Dim i As Long
    
    Set lbx = Worksheets("Sheet1").ListBox1
    
    With Range("MyNamedRange")
        For i = 1 To .Rows.Count
            If UCase(.Cells(i, 2).Value) = "ACTIVE" Then
                lbx.AddItem .Cells(i, 1).Value
                lbx.List(lbx.ListCount - 1, 1) = .Cells(i, 2).Value
            End If
        Next i
    End With

Change the sheet name, and the name of your named range, accordingly.

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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