PDA

View Full Version : State/county combo box



prasadksu
05-04-2011, 11:03 PM
Is it possible to do a State/County combo box scenario in an user form. I mean creating a "State" combo box in one column with all the states in the U.S. and a "County" combo box in the adjacent column. Is it possible to configure the two combo boxes so that if you choose NC for example in the State combo
box, the only choices available in the County combo box are NC counties. Once selected the data should enter into a cell in excel sheet.

I am new to VBA and any example of doing it would be greatly appreciated.

Thanks,
Prasad.

Bob Phillips
05-05-2011, 01:02 AM
Add a worksheet and in the columns add the counties for each state. Add a defined name for each of thes county lists, I called mine _stateAL, _stateAK, _stateAZ, ..., _stateNC, ... etc. where my state list contained a list of state abbreviations, AL, AK, AZ, etc.

Then in the userform I added



Private Sub cmbState_Change()
With Me.cmbCounty

.Clear
.List = Application.Transpose(Worksheets("Counties").Range("_state" & Me.cmbState.Value))
End With
End Sub

where the name of my county combobox is cmbCounty.