MarioExcelNoob
New Member
- Joined
- Nov 9, 2018
- Messages
- 6
hello all
I've been searching for this silly issue for 2 hours online now, on all kind of forums, but without success....
So i'm making this post, hoping someone can help me with my issue.
It shouldn't be very hard, but for some reason, i keep missing something.
Basicly i have a userform with 2 comboboxes. cmbPostalcode and cmbCity.
Now, in Belgium we can have multiple cities with the same postalcode (mainly if smaller villages around bigger cities).
The goal is simple enough: select a postal code, fill the second combobox with only the cities corresponding to that postal code (could be 1 city, could be 5...)
I have the table tblPostcodes in sheet "Lists".
postalcodes in column 'U', cities in 'V'. The columns have headers, so data starts on row 2.
I found how to fill cmbPostalcode with the UNIQUE values from that table, but i fail to link the corresponding cities in the cmbCity combobox.
the current code that is not working:
(i dont get errors, cmbCity is just not getting filled)
thanks in advance!
I've been searching for this silly issue for 2 hours online now, on all kind of forums, but without success....
So i'm making this post, hoping someone can help me with my issue.
It shouldn't be very hard, but for some reason, i keep missing something.
Basicly i have a userform with 2 comboboxes. cmbPostalcode and cmbCity.
Now, in Belgium we can have multiple cities with the same postalcode (mainly if smaller villages around bigger cities).
The goal is simple enough: select a postal code, fill the second combobox with only the cities corresponding to that postal code (could be 1 city, could be 5...)
I have the table tblPostcodes in sheet "Lists".
postalcodes in column 'U', cities in 'V'. The columns have headers, so data starts on row 2.
I found how to fill cmbPostalcode with the UNIQUE values from that table, but i fail to link the corresponding cities in the cmbCity combobox.
the current code that is not working:
(i dont get errors, cmbCity is just not getting filled)
VBA Code:
Private Sub cmbPostalcode_DropButtonClick()
Dim vList, d As Object, i As Long
vList = Sheets("Lists").Range("U2", Sheets("Lists").Cells(Rows.Count, "U").End(xlUp)).Value
Set d = CreateObject("scripting.dictionary")
d.CompareMode = vbBinaryCompare
For i = LBound(vList) To UBound(vList)
d(vList(i, 1)) = 1
Next
cmbPostalcode.List = d.keys
cmbCity.Text = ""
End Sub
Private Sub cmbCity_DropButtonClick()
Dim vList, d As Object, i As Long
vList = Sheets("Lists").Range("U2", Sheets("Lists").Cells(Rows.Count, "V").End(xlUp)).Value
Set d = CreateObject("scripting.dictionary")
d.CompareMode = vbBinaryCompare
For i = LBound(vList) To UBound(vList)
If vList(i, 1) = cmbPostalcode.Value Then d(vList(i, 2)) = 1
Next
cmbCity.List = d.keys
End Sub
thanks in advance!