Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1572to1576
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
ListBox mittels ComboBoxen filtern
07.08.2017 20:44:29
Markus
Liebes Forum,
wie es mein Betreff schon verrät, würde ich gerne wissen, ob man ComboBoxen auch als Filter für eine ListBox nutzen kann?
Eine ListBox anhand von abhängigen ComboBoxen konnte ich schon füllen. Nun ist mir die Idee gekommen, ob dies auch in die entgegengesetzte Richtung gehen würde. Also, dass man eine UserForm öffnet, in der sich die ListBox anhand des Inhaltes des Tabellenblatts automatisch füllt und man anschließend mittels der ComboBoxen die Filterung vornimmt. Die ComboBoxen sollten, wie beim Filter, voneinander abhängig sein.
Im Endeffekt kann man logischerweise auch einfach ein Filter über das Tabellenblatt legen und anschließend filtern.
Ich frage mal ganz frech, da für sowas meine VBA Kenntnisse nicht reichen. Hat vielleicht eine(r) von euch ein Makro, für ein einfaches Beispiel à la
- 3 Spalten: Stadt, Land und Fluss
- mit jeweils bspw. 5 Zeilen
Vielen Dank für eure Mühe im Voraus!

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: ListBox mittels ComboBoxen filtern
08.08.2017 08:13:57
fcs
Hallo Markus,
wie wäre es, wenn du als Vorarbeit schon maleine Beispieldatei erstellst mit Daten und Userform (inkl. Comboboxen und Listbox). Dann brauche Helfer dies nicht erst nachbauen.
So etwas macht aber eigentlich nur Sinn, wenn in der Listbox dann auch mehr als 1 Datensatz anzeigt werden sollen, dann sonst kann man auch die letzte Combobox so configurieren, dass der Inhalt des gewählten Eintrags in Textfeldern angezeigt wird.
Gruß
Franz
AW: ListBox mittels ComboBoxen filtern
08.08.2017 17:21:14
Markus
Hallo Franz,
erstmal Dank für deine Antwort. Habe heute etwas im Internet herumgesucht und folgender Code kam dabei raus und funktioniert einwandfrei.
Vielleicht kann jemand mit einem ähnlichen Anliegen das Makro gebrauchen:
Sind 5 ComboBoxen (5 Spalten) im Einsatz, welche sich auf die ersten 5 Zeilen beziehen, wobei in der ersten Zeile die jeweilige Überschrift steht.
Private Bypass As Boolean
Private Sub ComboBox1_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub

Private Sub ComboBox2_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub

Private Sub ComboBox3_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub
Private Sub ComboBox4_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub
Private Sub ComboBox5_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub

Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
' Bypass...
Bypass = True
' Comboboxen füllen...
FillCombobox "ComboBox1", 2, 1
FillCombobox "ComboBox2", 2, 2
FillCombobox "ComboBox3", 2, 3
FillCombobox "ComboBox4", 2, 4
FillCombobox "ComboBox5", 2, 5
' Listbox Einstellungen...
ListBox1.ColumnCount = 5
' Listbox füllen...
FillListbox 2, 1
' Bypass...
Bypass = False
End Sub

Private Function FillCombobox(Control As String, Row As Long, Column As Long)
Dim n As Long
Dim t As String
Dim v As String
Dim c As Collection
Dim d() As String
' Fehler abschalten...
On Error Resume Next
' Collection erzeugen...
Set c = New Collection
' Clear...
Me.Controls(Control).Clear
' Alles...
Me.Controls(Control).AddItem "All"
' Tabelle1...
With ThisWorkbook.Worksheets("Tabelle1")
'   Einlesen...
For n = 1 To 4
v = ""
v = .Cells(n + Row - 1, Column).Value
t = ""
t = c("Key=" & v)
If Len(t) 

Private Function FillListbox(Row As Long, Column As Long)
Dim b As Boolean
Dim n As Long
' Clear...
ListBox1.Clear
' Tabelle1...
With ThisWorkbook.Worksheets("Tabelle1")
'   Einlesen...
For n = 1 To 4
'     Reset...
b = True
'     Bedingungen...
If ComboBox1.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 0).Value)  _
(ComboBox1.List(ComboBox1.ListIndex, 0)))
End If
If ComboBox2.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 1).Value)  _
(ComboBox2.List(ComboBox2.ListIndex, 0)))
End If
If ComboBox3.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 2).Value)  _
(ComboBox3.List(ComboBox3.ListIndex, 0)))
End If
If ComboBox4.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 3).Value)  _
(ComboBox4.List(ComboBox4.ListIndex, 0)))
End If
If ComboBox5.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 4).Value)  _
(ComboBox5.List(ComboBox5.ListIndex, 0)))
End If
'     Hinzufügen...
If b Then
ListBox1.AddItem
ListBox1.List(ListBox1.ListCount - 1, 0) = .Cells(n + Row - 1, Column + 0).Value
ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(n + Row - 1, Column + 1).Value
ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(n + Row - 1, Column + 2).Value
ListBox1.List(ListBox1.ListCount - 1, 3) = .Cells(n + Row - 1, Column + 3).Value
ListBox1.List(ListBox1.ListCount - 1, 4) = .Cells(n + Row - 1, Column + 4).Value
End If
Next
End With
' Index...
If ListBox1.ListCount > 0 Then
ListBox1.ListIndex = 0
End If
End Function
Danke dir auch Franz für deinen Einsatz hier im Forum. Hast mir schon paar mal geholfen :)
Beste Grüße
Anzeige

300 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige