AW: Autofilterfunktion
16.10.2021 04:54:33
Werner
Hallo,
1. würde ich die Comboboxen über das Initialize der Userform und da dann über ein Scripting Dictionary füllen. Ein Scripting Dictionary kann nur eindeutige Werte aufnehmen. Das hat den Vorteil, dass du in deinen Comboboxen keine doppelten Werte hast.
Du musst jetzt aber bei allen Comboboxen die RowSource Eintragungen in den Eigenschaften wieder löschen.
Die Zuweisung der Einträge im Dictionary erfolgen über die List Eingenschaft der Combobox.
Private Sub UserForm_Initialize()
Dim myDic As Object, raZelle As Range
Set myDic = CreateObject("Scripting.Dictionary")
With Worksheets("Tabelle1")
loLetzte = .Cells(.Rows.Count, "B").End(xlUp).Row
For Each raZelle In .Range(.Cells(2, "B"), .Cells(loLetzte, "B"))
myDic(raZelle.Value) = 0
Next raZelle
Me.ComboBox1.List = myDic.keys
loLetzte = .Cells(.Rows.Count, "C").End(xlUp).Row
Set myDic = CreateObject("Scripting.Dictionary")
For Each raZelle In .Range(.Cells(2, "C"), .Cells(loLetzte, "C"))
myDic(raZelle.Value) = 0
Next raZelle
Me.ComboBox2.List = myDic.keys
Me.ComboBox3.List = myDic.keys
loLetzte = .Cells(.Rows.Count, "D").End(xlUp).Row
Set myDic = CreateObject("Scripting.Dictionary")
For Each raZelle In .Range(.Cells(2, "D"), .Cells(loLetzte, "D"))
myDic(raZelle.Value) = 0
Next raZelle
Me.ComboBox4.List = myDic.keys
End With
Set myDic = Nothing
End Sub
Ansonsten:
Private Sub CommandButton1_Click()
If Me.ComboBox1.ListIndex > -1 Then
Worksheets("Tabelle1").Range("A1").AutoFilter Field:=2, Criteria1:="=" & ComboBox1
End Sub
Private Sub CommandButton2_Click()
If Me.ComboBox2.ListIndex > -1 And Me.ComboBox3.ListIndex > -1 Then
Worksheets("Tabelle1").Range("A1").AutoFilter Field:=3, Criteria1:=">=" & ComboBox2, _
Operator:=xlAnd, Criteria2:=" -1 Then
Worksheets("Tabelle1").Range("A1").AutoFilter Field:=4, Criteria1:=CLng(ComboBox4)
End If
End Sub
Gruß Werner