<<Convert Excel Spreadsheets to Web Pages | Trading Software That Operates Within Excel | Convert Excel, Access & Other Databases | Merge Excel Files>> |
---|
Filling a ListBox and ComboBox Using Loops
While
using the RowSource Property referring to a range is the most likely way to fill
a ListBox and ComboBox and probably the easiest way. There are times when the
AddItem method is a better option and in some cases the only option. Let’s say
that you want to fill a ComboBox or ListBox with times that cover the previous
24 hour period at 15 minute intervals. You could of course use the NOW()
Function on a hidden Worksheet and increment it by the needed increment, ie;
A1
= NOW()
A2
=
A1+0.0104166666666667
A3=
A2+0.0104166666666667
And
so on……
This Loop will fill our ListBox with times that are incremented at 15 minute intervals over a 24 hour period. The code will only run when the UserForm that houses the ListBox is initialised. We could of course have the code run via a CommandButton or many other methods.
Summary
So
as you can see there does need to be some foresight as to which Control is best
suited to a particular situation. At times you may even use both the ComboBox
and ListBox.