ich bin gerade dabei eine Userfor zu erstellen, bei der ich zwei Comboboxen eingefügt habe, welche sich beide in Abhängigkeit füllen (also Combo 2 ost abhängig von Combo 1).
Jetzt habe ich allerdings nicht nur 2 Spalten in meiner Tabelle sondern mehr als 10.
Nach dem die Comboboxen ausgefüllt sind, würde ich jetzt gerne die restlichen Spalten aus der Reihe in eine Textbox eintragen lassen.
Den Code habe ich mir aus dem Internet zusammengesucht und Teile davon abgeändert. Mein Problem ist jetzt nur das in der Textbox1 leider die falschen Ergebnisse angezeigt werden. Könnt ihr mir vielleicht helfen? Meine Problemzeile habe ich fettgedruck.
Wäre super wenn ihr mir helfen könntet
Grüße Manuel
Option Explicit
Const C_mstrDatenblatt As String = "Parts"
Const C_mstrZielblatt As String = "Plastic"
Dim mobjDic As Object
Dim mlngLast As Long
Dim mlngZ As Long
Private Sub ComboBox1_Enter()
Set mobjDic = CreateObject("Scripting.Dictionary")
For mlngZ = 2 To mlngLast
mobjDic(Worksheets(C_mstrDatenblatt).Cells(mlngZ, 1).Value) = 0
Next
Me.ComboBox1.List = mobjDic.keys
Set mobjDic = Nothing
End Sub
Private Sub ComboBox2_Enter()
Set mobjDic = CreateObject("Scripting.Dictionary")
With Worksheets(C_mstrDatenblatt)
For mlngZ = 2 To mlngLast
If .Cells(mlngZ, 1).Value = Me.ComboBox1.Value Then
mobjDic(.Cells(mlngZ, 2).Value) = 0
End If
Next
End With
Me.ComboBox2.List = mobjDic.keys
Set mobjDic = Nothing
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub ComboBox2_Click()
If ComboBox2.ListIndex 0 Then
Sheets("Parts").Activate
TextBox1 = Sheets("Parts").Cells(ComboBox2.ListIndex + 2, 4)
Else
Sheets("Parts").Activate
TextBox1 = Sheets("Parts").Cells(ComboBox2.ListIndex + 2, 4)
End If
End Sub
Private Sub CommandButton2_Click()
'Ausgewählte Daten in Tabelle 2 übertragen
Sheets("Plastic").Activate
ActiveSheet.Unprotect
With Worksheets(C_mstrZielblatt)
.Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1).Value = Me.ComboBox1.Value
.Cells(.Cells(Rows.Count, 2).End(xlUp).Row + 1, 2).Value = Me.ComboBox2.Value
.Cells(.Cells(Rows.Count, 3).End(xlUp).Row + 1, 3).Value = Me.ComboBox3.Value
End With
End Sub
Private Sub UserForm_Initialize()
'Bei Start der Userform wird die unterste Zeile in Spalte A ermittelt
mlngLast = Worksheets(C_mstrDatenblatt).Cells(Rows.Count, 1).End(xlUp).Row
End Sub