Populating A Combo Box On A Form Using VBA

CaliKidd

Board Regular
Joined
Feb 16, 2011
Messages
173
I am using Excel 2007 and I have designed a form that has several combo boxes. Currently, I am populating the combo boxes thru VBA by using .additem. For example, one combo box might be:

Code:
        With .City
            .AddItem "Abilene"
            .AddItem "Abbotsford"
            .AddItem "Abidjan"
            .AddItem "Adana"
            .AddItem "Addis Ababa"
            .AddItem "Adelaide"
            .AddItem "Ahmedabad"
            .AddItem "Akron"
etc...
        End With

The problem with hard-coding it this way is the amount of effort in maintaining the code; that is, every time I want to update the entries, I have to modify the code. Since multiple people will be using this Excel workbook separately (i.e., not a shared workbook), I would have to release a new revision every time I made changes like this.

So, I have a few design questions:

1. I'm considering the idea of putting this list of entries in a separate file (database table) so that I could update this table independently, as needed (instead of having to update the VBA code and issue a new revision of the program). Can you give me an example of how could I write a For-Next loop that would best accomplish this? Assume the database (Access or SQL) is not local, but on a webhost server (internet site).

2. How big of a performance hit would it be for VBA to pull in data from an external source vs having it hardcoded internally? I know it's a very subjective question, but I hoping that someone may have some experience in this area and can answer it or provide a better approach. I'm trying to weigh the ease of maintenance vs performance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

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