ListBox population from Excel range

  • Thread starter Thread starter Tim Coddington
  • Start date Start date
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
(e-mail address removed)

Shane
Bobber
1
(e-mail address removed)

Sean
Cantral
1
(e-mail address removed)

Bobby
Smith
3
(e-mail address removed)

Lucy
Johnson
1
(e-mail address removed)

Linn
Cenad
2
(e-mail address removed)



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?
 
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.
 
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top