There are two comboboxes:
CityBox <- Contains names of various cities
AddrBox <- Contains addresses of various locations
Both are located on a userform but AddrBox is disabled until an item in CityBox is selected. Each is being populated via the RowSource object which is pulling data from an Excel spreadsheet in this format:
City Name | # of Locations | Address 1 | Address 2 | Address3 | etc... |
Now the code is supposed to populate AddrBox once the user selects a city from CityBox. The problem is only the first address (Address 1) is coming up in AddrBox.
CitySheet is a global variable that is assigned in the UserForm_Initialize routine and CityBox uses the RowSource to assign the values:
----------------------------------------
If you are reading this, then you have read too far...
CityBox <- Contains names of various cities
AddrBox <- Contains addresses of various locations
Both are located on a userform but AddrBox is disabled until an item in CityBox is selected. Each is being populated via the RowSource object which is pulling data from an Excel spreadsheet in this format:
City Name | # of Locations | Address 1 | Address 2 | Address3 | etc... |
Now the code is supposed to populate AddrBox once the user selects a city from CityBox. The problem is only the first address (Address 1) is coming up in AddrBox.
Code:
Private Sub CityBox_Change()
Dim StartPos, EndPos As String
Dim AddrTotal, Pos As Integer
AddrBox.Enabled = True
Pos = CityBox.ListIndex + 1
' Excludes initialization
If Pos > 0 Then
AddrTotal = CitySheet.Cells(Pos, 2).Value + 2
StartPos = CitySheet.Cells(Pos, 3).Address
EndPos = CitySheet.Cells(Pos, AddrTotal).Address
AddrBox.RowSource = StartPos & ":" & EndPos
End If
End Sub
CitySheet is a global variable that is assigned in the UserForm_Initialize routine and CityBox uses the RowSource to assign the values:
Code:
Set CitySheet = Worksheets(2)
CityBox.RowSource = "A1:A24"
----------------------------------------
If you are reading this, then you have read too far...