ListBox population from Excel range

T

Tim Coddington

Ok. Figured out how to load a list box
from an Excel range, like so ...

Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 4
ListBox1.RowSource = "A2:D" & Cells(1, 1).End(xlDown).Row
End Sub

Sample of spreadsheet values follows:
Name, First
Name, Last
Class
Address

Amber
Boger
2
[email protected]

Shane
Bobber
1
[email protected]

Sean
Cantral
1
[email protected]

Bobby
Smith
3
[email protected]

Lucy
Johnson
1
[email protected]

Linn
Cenad
2
[email protected]



Now I need to load ListBox1 from the same range, but only data
from a certain class, say 2. The list box would pick up Amber and
Linn, but not Sean (because he is class 1). Is there a way to do that?
 
D

Dick Kusleika

B

Ben Palmer

When the form is initialised, use the Clear Method to clear the list
box and then loop through your database and use the AddItem Method to
add data to the listbox if the class field meets your criteria.
 
T

Tim Coddington

Thanks Dick! Thanks Ben!
This also helps me understand how to use List and ListCount to
populate the second, third, and fourth columns.
Great news group!
 
Top