Gruppe
Dialog
Bereich
ComboBox
Thema
ComboBox mit der Funktion des Autofilters
Problem
Eine ComboBox in einem Tabellenblatt soll die Funktion des Autofilters erfüllen.
Lösung
Geben Sie den Ereigniscode in das Klassenmodul des Arbeitsblattes ein.
ClassModule: Tabelle1
Private Sub ComboBox1_Change()
Dim iRow As Integer
If ComboBox1.Value = "" Then Exit Sub
Rows.Hidden = False
iRow = 2
Do Until IsEmpty(Cells(iRow, 1))
If Cells(iRow, 1).Value <> CInt(ComboBox1.Value) Then
Rows(iRow).Hidden = True
End If
iRow = iRow + 1
Loop
End Sub
Private Sub ComboBox1_DropButtonClick()
Dim col As New Collection
Dim iRow As Integer
ComboBox1.Clear
Range("A1").CurrentRegion.Sort _
key1:=Range("A2"), order1:=xlAscending, header:=xlYes
iRow = 2
On Error Resume Next
Do Until IsEmpty(Cells(iRow, 1))
col.Add CStr(Cells(iRow, 1).Value), CStr(Cells(iRow, 1).Value)
iRow = iRow + 1
Loop
On Error GoTo 0
For iRow = 1 To col.Count
ComboBox1.AddItem col(iRow)
Next iRow
End Sub