Here is all the code (in the 'Store Tracker' sheet module)
You can select the ID, and you will see the store's name in the second combo. Or you can choose the name of the store and you will see its ID in the first combo.
Option Explicit
Option Compare Text
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim x, txt$, i&, s$
x = Sheets("Location Plan").Range("Store_Name").Value
txt = Me.ComboBox1.Value
For i = 1 To UBound(x)
If InStr(x(i, 1), txt) Then s = s & "~" & x(i, 1)
Next
Me.ComboBox1.List = Split(Mid(s, 2), "~")
Me.ComboBox1.DropDown
End Sub
Private Sub ComboBox2_Change()
Dim s$
On Error Resume Next
s = WorksheetFunction.VLookup(Val(ComboBox2.Value), Sheets("Location Plan").Range("A5:B1500"), 2, 0)
Me.ComboBox1.Value = s
End Sub
Private Sub ComboBox1_Change()
On Error Resume Next
With WorksheetFunction
Me.ComboBox2.Value = .Index(Sheets("Location Plan").Range("A5:A1500"), _
.Match(ComboBox1.Value, Sheets("Location Plan").Range("B5:B1500"), 0))
End With
End Sub
Bookmarks