Dim sh1 As Worksheet '[COLOR=#0000ff]This line should go to the beginning of all the code![/COLOR]
Private Sub ComboBox1_Change()
Dim a() As Variant, dict As Object, i As Long
ComboBox2.Clear
ComboBox3.Clear
ComboBox4.Clear
ComboBox2.Value = ""
ComboBox3.Value = ""
ComboBox4.Value = ""
If ComboBox1 = "" Or ComboBox1.ListIndex = -1 Then Exit Sub
'
a = sh1.Range("A2", sh1.Range("B" & Rows.Count).End(xlUp))
Set dict = CreateObject("scripting.dictionary")
For i = 1 To UBound(a)
If a(i, 1) = ComboBox1 Then
If Not dict.exists(a(i, 2)) Then
dict(a(i, 2)) = dict(a(i, 2))
ComboBox2.AddItem a(i, 2)
End If
End If
Next
End Sub
Private Sub ComboBox2_Change()
Dim a() As Variant, dict As Object, i As Long
ComboBox3.Clear
ComboBox4.Clear
ComboBox3.Value = ""
ComboBox4.Value = ""
If ComboBox2 = "" Or ComboBox2.ListIndex = -1 Then Exit Sub
'
a = sh1.Range("A2", sh1.Range("C" & Rows.Count).End(xlUp))
Set dict = CreateObject("scripting.dictionary")
For i = 1 To UBound(a)
If a(i, 1) = ComboBox1 And a(i, 2) = ComboBox2 Then
If Not dict.exists(a(i, 3)) Then
dict(a(i, 3)) = dict(a(i, 3))
ComboBox3.AddItem a(i, 3)
End If
End If
Next
End Sub
Private Sub ComboBox3_Change()
Dim a() As Variant, dict As Object, i As Long
ComboBox4.Clear
ComboBox4.Value = ""
If ComboBox3 = "" Or ComboBox3.ListIndex = -1 Then Exit Sub
'
a = sh1.Range("A2", sh1.Range("D" & Rows.Count).End(xlUp))
Set dict = CreateObject("scripting.dictionary")
For i = 1 To UBound(a)
If a(i, 1) = ComboBox1 And a(i, 2) = ComboBox2 And a(i, 3) = ComboBox3 Then
If Not dict.exists(a(i, 4)) Then
dict(a(i, 4)) = dict(a(i, 4))
ComboBox4.AddItem a(i, 4)
End If
End If
Next
End Sub
Private Sub CommandButton1_Click()
LastRow = ThisWorkbook.Worksheets("Purchase Tracker").Cells(Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 2).Value = DTPicker1.Value
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 3).Value = ComboBox1.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 4).Value = ComboBox2.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 5).Value = ComboBox3.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 6).Value = ComboBox4.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 7).Value = ComboBox5.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 1).Value = TextBox1.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 8).Value = ComboBox6.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 9).Value = TextBox2.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 10).Value = TextBox3.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 11).Value = TextBox4.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 12).Value = ComboBox7.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 13).Value = ComboBox8.Text
ThisWorkbook.Worksheets("Purchase Tracker").Cells(LastRow + 1, 14).Value = TextBox5.Text
End Sub
Private Sub CommandButton2_Click()
ThisWorkbook.Sheets("Main").Activate
Unload Me
End Sub
Private Sub UserForm_Activate()
Dim a() As Variant, dict As Object, i As Long
'
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then ctl.Value = ""
Next ctl
'
Set sh1 = Sheets("ProductList")
a = sh1.Range("A2", sh1.Range("A" & Rows.Count).End(xlUp))
Set dict = CreateObject("scripting.dictionary")
For i = 1 To UBound(a)
If Not dict.exists(a(i, 1)) Then
dict(a(i, 1)) = dict(a(i, 1))
ComboBox1.AddItem a(i, 1)
End If
Next
End Sub