Textbox von ComboBox abhängig
Betrifft: Textbox von ComboBox abhängig
von: Andreas
Geschrieben am: 08.10.2014 09:36:11
Hallo Excelprofis,
Ich habe hier im Forum nachfolgenden Code gefunden und angepasst. Bei einem Schritt komme ich aber nicht weiter:
ComboBoxOrt ist abhängig von ComboBoxStr - ComboBoxTransp ist abhängig von ComboBoxOrt.
Ereichen möchte ich, dass statt der ComboBoxTransp eine Textbox angesprochen wird, da hier jeweils nur 1 Wert vorkommen kann.
Kann mir bitte Jemand helfen, probiere schon seit 2 Stunden vergeblich.
Hier der Code:
Private Sub UserForm_Initialize()
Dim hshA As Object
Dim i As Long
Set hshA = CreateObject("Scripting.Dictionary")
With ThisWorkbook.Sheets("Strassen")
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
hshA(.Cells(i, 1).Text) = 0
Next
Me.ComboBoxStr.List = hshA.Keys
End With
Set hshA = Nothing
End Sub
Private Sub ComboBoxStr_Change()
Dim hshB As Object
Dim i As Long
Set hshB = CreateObject("Scripting.Dictionary")
Me.ComboBoxOrt.Clear
Me.ComboBoxTransp.Clear
With ThisWorkbook.Sheets("Strassen")
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
If .Cells(i, 1) = Me.ComboBoxStr Then
hshB(.Cells(i, 2).Text) = 0
End If
Next
Me.ComboBoxOrt.List = hshB.Keys
End With
Set hshB = Nothing
End Sub
Private Sub ComboBoxOrt_Change()
Dim hshC As Object
Dim i As Long
Set hshC = CreateObject("Scripting.Dictionary")
Me.ComboBoxTransp.Clear
With ThisWorkbook.Sheets("Strassen")
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
If .Cells(i, 2) = Me.ComboBoxOrt Then
hshC(.Cells(i, 3).Text) = 0
End If
Next
Me.ComboBoxTransp.List = hshC.Keys
End With
Set hshC = Nothing
End Sub
Danke fürs lesen!
mfg, Andreas
Betrifft: AW: Textbox von ComboBox abhängig
von: Franc
Geschrieben am: 09.10.2014 05:10:40
wenn nur ein wert vorkommen kann
Das exit for dient dazu, das er die for to next Schleife verlässt nachdem er den Wert gefunden hat.
Private Sub ComboBoxOrt_Change()
Dim i As Long
With ThisWorkbook.Sheets("Strassen")
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
If .Cells(i, 2) = Me.ComboBoxOrt Then
me.textboxname.text = .Cells(i, 3).Text
exit for
End If
Next
End With
End Sub
Kann man natürlich auch mit einer Suchfunktion lösen aber wenn nicht all zu viele Orte/Zeilen vorhanden sind, ist das von der Performance fast egal.
Betrifft: AW: Textbox von ComboBox abhängig
von: Andreas
Geschrieben am: 09.10.2014 10:28:20
Hallo Franc,
Habe deinen Code getestet, funktioniert genau wie gedacht.
Vielen Dank für deine Hilfe und einen schönen Tag noch.
mfg, Andreas
Beiträge aus den Excel-Beispielen zum Thema "Textbox von ComboBox abhängig"