Populating a ListBox with Filtered data

underpressure

Board Regular
Joined
Nov 24, 2012
Messages
141
I’m attempting to display only the Active Members in my database (Sheet11).
This code populates ListBox1 with the entire database Range (C2:C).
How can I modify the code to show only the Filtered Range?

Code:
Private Sub CommandButton4_Click()
If CommandButton4.Caption = "View Active Roster" Then
 
Sheet11.Select
    Selection.AutoFilter
       ActiveSheet.Range("$A$1:$FY$267").AutoFilter Field:=14, Criteria1:="A"
 
With Sheet11
    ListBox1.List = .Range("C2", .Range("C" & .Rows.Count).End(xlUp)).Resize(, 1).Value
End With
 
ListBox1.Visible = True
 Label1.Visible = True
  CommandButton4.Caption = "Close Active Roster"
   Label1.Caption = Sheet11.[C1].Value
 
Else

ListBox1.Visible = False
 CommandButton4.Caption = "View Active Roster"
  Label1.Visible = False
   Selection.AutoFilter
End If
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Either copy the visible cells to a temp sheet & load the listbox from there, or loop through the visible cells adding to the listbox row by row.
 
Upvote 0
Maybe this:

Code:
Dim r As Range
ListBox1.Clear
With Sheet11
    For Each r In .Range("C2", .Cells(.Rows.count, "C").End(xlUp)).SpecialCells(xlCellTypeVisible)
    ListBox1.AddItem r
    Next
End With
 
Upvote 0

Forum statistics

Threads
1,215,644
Messages
6,125,991
Members
449,278
Latest member
MOMOBI

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