Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1384to1388
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
Textbox von ComboBox abhängig
08.10.2014 09:36:11
ComboBox
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

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

Betreff
Datum
Anwender
Anzeige
AW: Textbox von ComboBox abhängig
09.10.2014 05:10:40
ComboBox
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.

Anzeige
AW: Textbox von ComboBox abhängig
09.10.2014 10:28:20
ComboBox
Hallo Franc,
Habe deinen Code getestet, funktioniert genau wie gedacht.
Vielen Dank für deine Hilfe und einen schönen Tag noch.
mfg, Andreas

179 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige