Replace whole code in UserForm code module with the following code.
Option Explicit
Private dic As Object
Private Sub UserForm_Initialize()
Dim a, i As Long, ii As Long
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("brand").Cells(1).CurrentRegion
a = .Parent.Evaluate(.Address & "&""""")
End With
For i = 2 To UBound(a, 1)
If Not dic.exists(a(i, 1)) Then
Set dic(a(i, 1)) = CreateObject("Scripting.Dictionary")
End If
If Not dic(a(i, 1)).exists(a(i, 2)) Then
Set dic(a(i, 1))(a(i, 2)) = CreateObject("Scripting.Dictionary")
End If
dic(a(i, 1))(a(i, 2))(a(i, 3)) = Array(a(i, 4), a(i, 5))
Next
Me.ComboBox1.List = dic.keys
End Sub
Private Sub ComboBox1_Click()
Me.ComboBox2.Clear
Me.ComboBox3.Clear
Me.ComboBox2.List = dic(Me.ComboBox1.Value).keys
GetPrice
End Sub
Private Sub ComboBox2_Click()
Me.ComboBox3.Clear
Me.ComboBox3.List = dic(Me.ComboBox1.Value)(Me.ComboBox2.Value).keys
GetPrice
End Sub
Private Sub ComboBox3_Click()
GetPrice
End Sub
Private Sub TextBox1_AFTERUPDATE()
With Me.TextBox1
If IsNumeric(.Value) Then .Value = Format(.Value, "$#,##0.00")
End With
End Sub
Private Sub OptionButton1_Click()
GetPrice
End Sub
Private Sub OptionButton2_Click()
GetPrice
End Sub
Private Sub GetPrice()
Dim i As Long, myCol As Long
Me.TextBox1 = ""
For i = 1 To 3
If Me("combobox" & i).ListIndex = -1 Then Exit Sub
Next
If Not dic.exists(Me.ComboBox1.Value) Then Exit Sub
If Not dic(Me.ComboBox1.Value).exists(Me.ComboBox2.Value) Then Exit Sub
If Not dic(Me.ComboBox1.Value)(Me.ComboBox2.Value).exists(Me.ComboBox3.Value) Then Exit Sub
For i = 1 To 2
If Me("optionbutton" & i) Then Exit For
Next
If i < 3 Then Me.TextBox1 = Format$(dic(Me.ComboBox1.Value)(Me.ComboBox2.Value)(Me.ComboBox3.Value)(i - 1), "$#,##0.00")
End Sub
Bookmarks