quemuenchatocha
Board Regular
- Joined
- Aug 4, 2021
- Messages
- 50
- Office Version
- 365
- 2019
- Platform
- Windows
Hi, I am working on a userform that calculates the distance between two cities (measured along a straight line) expressed in miles and kilometres. To make this possible, four ComboBoxes have been entered into the form, two of them record the State, while the remaining two contain the city corresponding to each selected State. For City #1:, the code works correctly, both for the city and the state, while for City #2:, when opening the form, the option appears blank as shown in the image. However, I can select the State, with its respective cities, but these are not displayed.
I have entered the following code and I can't find where the fault lies
I would be grateful if you could tell me what mistake I am making or give me some advice on how to solve this problem. Thank you very much for your attention.
ps: if necessary, in the following link I leave the book where you can find the complete code.
Workbook Example
I have entered the following code and I can't find where the fault lies
VBA Code:
Option Explicit
Public nStates as Integer, nCities as Integer
Sub PopulateStates()
Dim i As Integer
Sheets("Main").Select
Range("A1").Select
Sheets("Sheet1").Select
nStates = WorksheetFunction.CountA(Columns("E:E"))
nCities = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row - 2
For i = 1 To nStates
UserForm1.state1select.AddItem Range("E1:E" & nStates).Cells(i, 1)
UserForm1.state2select.AddItem Range("E1:E" & nStates).Cells(i, 1)
Next i
UserForm1.state1select.Text = Range("E1:E" & nStates).Cells(1, 1)
UserForm1.state2select.Text = Range("E1:E" & nStates).Cells(1, 1)
End Sub
I would be grateful if you could tell me what mistake I am making or give me some advice on how to solve this problem. Thank you very much for your attention.
ps: if necessary, in the following link I leave the book where you can find the complete code.
Workbook Example