AW: Combobox2 abhängig von Combobox1
13.11.2019 16:57:38
Combobox1
Hallo Bernd,
Du hättest mit dem Links ja auch einfach weiter googeln können :-)
hier mal etwas zu testen,
einmal als Combobox 1 und 2
Private Sub ComboBox1_GotFocus()
Sheets("Tabelle1").ComboBox1.Clear
Dim objDic As Object
Dim Bereich As Range
Dim Zelle As Range
Set objDic = CreateObject("Scripting.Dictionary")
Set Bereich = Sheets("Tabelle1").Range("B3:B100") 'relevanten Bereich ermitteln
For Each Zelle In Bereich
objDic(Zelle.Value) = 0 'Nur Unikate sammeln
Next
Sheets("Tabelle1").ComboBox1.List = objDic.keys 'Unikate der ComboBox zuweisen
End Sub
Private Sub ComboBox2_GotFocus()
Sheets("Tabelle1").ComboBox2.Clear
For ze = 3 To Cells(Rows.Count, 2).End(xlUp).Row
If Sheets("Tabelle1").Cells(ze, 2) = CDate(Sheets("Tabelle1").ComboBox1.Text) Then
ComboBox2.AddItem Sheets("Tabelle1").Cells(ze, 3)
End If
Next
End Sub
und einmal als ListBox 1 und 2
Private Sub ListBox1_GotFocus()
Sheets("Tabelle1").ListBox1.Clear
Dim objDic As Object
Dim Bereich As Range
Dim Zelle As Range
Set objDic = CreateObject("Scripting.Dictionary")
Set Bereich = Sheets("Tabelle1").Range("B3:B100") 'relevanten Bereich ermitteln
For Each Zelle In Bereich
objDic(Zelle.Value) = 0 'Nur Unikate sammeln
Next
Sheets("Tabelle1").ListBox1.List = objDic.keys 'Unikate der ComboBox zuweisen
End Sub
Private Sub ListBox2_GotFocus()
Sheets("Tabelle1").ListBox2.Clear
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
For ze = 3 To Sheets("Tabelle1").Cells(Rows.Count, 2).End(xlUp).Row
If Sheets("Tabelle1").Cells(ze, 2) = ListBox1.List(x) Then
ListBox2.AddItem Sheets("Tabelle1").Cells(ze, 3)
End If
Next
End If
Next
End Sub
Gruß
Jochen