Option Explicit
Private Sub UserForm_Initialize()
Dim c As Range
Me.ComboBox1.AddItem "(All)"
For Each c In Sheet2.Range("B1").CurrentRegion.Offset(0, 1).Rows(1).Cells
If c.Value <> "" Then
Me.ComboBox1.Value = c.Value
If Me.ComboBox1.ListIndex = -1 Then Me.ComboBox1.AddItem c.Value
End If
Next c
Me.ComboBox1.ListIndex = 0
End Sub
Private Sub ComboBox1_Change()
Dim Brand As String
Dim c As Range
Me.ComboBox2.Clear
Me.ComboBox2.AddItem "(All)"
If Me.ComboBox1.ListIndex > -1 Then
Brand = Me.ComboBox1.Value
If Brand = "(All)" Then Brand = "*"
For Each c In Sheet2.Range("B1").CurrentRegion.Offset(0, 1).Rows(1).Cells
If c.Value Like Brand And c.Offset(1, 0).Value <> "" Then
Me.ComboBox2.Value = c.Offset(1, 0).Value
If Me.ComboBox2.ListIndex = -1 Then Me.ComboBox2.AddItem c.Offset(1, 0).Value
End If
Next c
End If
Me.ComboBox2.ListIndex = 0
End Sub
Private Sub ComboBox2_Change()
Dim Typ As String
Dim c As Range
Me.ComboBox3.Clear
Me.ComboBox3.AddItem "(All)"
If Me.ComboBox2.ListIndex > -1 Then
Typ = Me.ComboBox2.Value
If Typ = "(All)" Then Typ = "*"
For Each c In Sheet2.Range("B1").CurrentRegion.Offset(0, 1).Rows(2).Cells
If c.Value Like Typ And c.Offset(1, 0).Value <> "" Then
Me.ComboBox3.Value = c.Offset(1, 0).Value
If Me.ComboBox3.ListIndex = -1 Then Me.ComboBox3.AddItem c.Offset(1, 0).Value
End If
Next c
End If
Me.ComboBox3.ListIndex = 0
End Sub
Private Sub CommandButton1_Click()
Dim Brand As String, Typ As String, Colr As String
Dim Plage As Range, c As Range
Brand = Me.ComboBox1.Value
If Brand = "(All)" Then Brand = "*"
Typ = Me.ComboBox2.Value
If Typ = "(All)" Then Typ = "*"
Colr = Me.ComboBox3.Value
If Colr = "(All)" Then Colr = "*"
With Sheet2
Set Plage = .Range("B:B")
For Each c In Sheet2.Range("B1").CurrentRegion.Offset(0, 1).Rows(1).Cells
If c.Value Like Brand And c.Offset(1, 0) Like Typ And c.Offset(2, 0) Like Colr Then Set Plage = Union(Plage, c.EntireColumn.Cells)
Next c
End With
With Sheet1
.UsedRange.Clear
Plage.Copy .Range("A1")
End With
Set Plage = Nothing
Unload Me
End Sub
Private Sub Cancel_Click()
Unload UserForm1
End Sub