Hi.
I am new to VBA, and i am trying to have the last Combo box (ComboBox2) to populate all the information from the sheet to the userform text boxes. It all works great, but i can only get it to populate to 2 of the 8 text boxes. If i add more lines so that it will populate to the other text boxes, i am getting an "Not in Range" type of error. I would apprecate any and all help i can get. Thanks
This is the code that i am attempting to use:
Option Explicit
Private dic As Object
Private Sub UserForm_Initialize()
Dim a, i As Long
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
a = Sheets("Hotels").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
If Not dic.Exists(a(i, 2)) Then
Set dic(a(i, 2)) = CreateObject("Scripting.Dictionary")
dic(a(i, 2)).CompareMode = 1
End If
If Not dic(a(i, 2)).Exists(a(i, 3)) Then
Set dic(a(i, 2))(a(i, 3)) = _
CreateObject("Scripting.Dictionary")
dic(a(i, 2))(a(i, 3)).CompareMode = 1
End If
dic(a(i, 2))(a(i, 3)) = VBA.Array(a(i, 4), a(i, 5))
Next
Me.cboCategory.List = dic.keys
End Sub
Private Sub cboCategory_Change()
With Me
.ComboBox2.Clear
.tbResCol1.Value = ""
.tbResCol2.Value = ""
If .cboCategory.ListIndex > -1 Then
.ComboBox2.List = dic(.cboCategory.Value).keys
End If
End With
End Sub
Private Sub ComboBox2_Change()
With Me
.tbResCol1.Value = ""
.tbResCol2.Value = ""
If .ComboBox2.ListIndex > -1 Then
.tbResCol3.Value = dic(.cboCategory.Value)(.ComboBox2.Value)(0)
.tbResCol4.Value = dic(.cboCategory.Value)(.ComboBox2.Value)(1)
End If
End With
End Sub
I am new to VBA, and i am trying to have the last Combo box (ComboBox2) to populate all the information from the sheet to the userform text boxes. It all works great, but i can only get it to populate to 2 of the 8 text boxes. If i add more lines so that it will populate to the other text boxes, i am getting an "Not in Range" type of error. I would apprecate any and all help i can get. Thanks
This is the code that i am attempting to use:
Option Explicit
Private dic As Object
Private Sub UserForm_Initialize()
Dim a, i As Long
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
a = Sheets("Hotels").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
If Not dic.Exists(a(i, 2)) Then
Set dic(a(i, 2)) = CreateObject("Scripting.Dictionary")
dic(a(i, 2)).CompareMode = 1
End If
If Not dic(a(i, 2)).Exists(a(i, 3)) Then
Set dic(a(i, 2))(a(i, 3)) = _
CreateObject("Scripting.Dictionary")
dic(a(i, 2))(a(i, 3)).CompareMode = 1
End If
dic(a(i, 2))(a(i, 3)) = VBA.Array(a(i, 4), a(i, 5))
Next
Me.cboCategory.List = dic.keys
End Sub
Private Sub cboCategory_Change()
With Me
.ComboBox2.Clear
.tbResCol1.Value = ""
.tbResCol2.Value = ""
If .cboCategory.ListIndex > -1 Then
.ComboBox2.List = dic(.cboCategory.Value).keys
End If
End With
End Sub
Private Sub ComboBox2_Change()
With Me
.tbResCol1.Value = ""
.tbResCol2.Value = ""
If .ComboBox2.ListIndex > -1 Then
.tbResCol3.Value = dic(.cboCategory.Value)(.ComboBox2.Value)(0)
.tbResCol4.Value = dic(.cboCategory.Value)(.ComboBox2.Value)(1)
End If
End With
End Sub