AW: ComboBox Tabellenwahl
06.02.2016 10:51:48
Floeh
Super funktioniert soweit ganz gut. Danke!
Jetzt ist es nur so: Wenn ich einen Eintrag aus ComboBox2 auswähle, bleiben die Textfelder leer. Es füllt sich allerdings, wenn ich in ComboBox1 einen Eintrag ausgewählt habe.
Private Sub ComboBox1_Change()
Dim i As Integer
With Sheets("Tabelle1")
If ComboBox1.ListIndex > -1 Then
TextBox1 = .Cells(ComboBox1.ListIndex + 1, 5)
TextBox2 = .Cells(ComboBox1.ListIndex + 1, 10)
TextBox3 = .Cells(ComboBox1.ListIndex + 1, 3)
TextBox4 = .Cells(ComboBox1.ListIndex + 1, 12)
TextBox5 = .Cells(ComboBox1.ListIndex + 1, 13)
Else
For i = 1 To 5
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub ComboBox2_Change()
Dim i As Integer
With Sheets("Tabelle2")
If ComboBox1.ListIndex > -1 Then
TextBox6 = .Cells(ComboBox2.ListIndex + 1, 5)
TextBox7 = .Cells(ComboBox2.ListIndex + 1, 10)
TextBox8 = .Cells(ComboBox2.ListIndex + 1, 3)
TextBox9 = .Cells(ComboBox2.ListIndex + 1, 12)
TextBox10 = .Cells(ComboBox2.ListIndex + 1, 13)
Else
For i = 6 To 10
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub ComboBox3_Change()
Dim i As Integer
With Sheets("Tabelle3")
If ComboBox1.ListIndex > -1 Then
TextBox11 = .Cells(ComboBox3.ListIndex + 1, 5)
TextBox12 = .Cells(ComboBox3.ListIndex + 1, 10)
TextBox13 = .Cells(ComboBox3.ListIndex + 1, 3)
TextBox14 = .Cells(ComboBox3.ListIndex + 1, 12)
TextBox15 = .Cells(ComboBox3.ListIndex + 1, 13)
Else
For i = 11 To 15
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub ComboBox4_Change()
Dim i As Integer
With Sheets("Tabelle4")
If ComboBox1.ListIndex > -1 Then
TextBox16 = .Cells(ComboBox4.ListIndex + 1, 5)
TextBox17 = .Cells(ComboBox4.ListIndex + 1, 10)
TextBox18 = .Cells(ComboBox4.ListIndex + 1, 3)
TextBox19 = .Cells(ComboBox4.ListIndex + 1, 12)
TextBox20 = .Cells(ComboBox4.ListIndex + 1, 13)
Else
For i = 16 To 20
Controls("TextBox" & i) = ""
Next
End If
End With
End Sub
Private Sub UserForm_Activate()
Dim varDaten1 As Variant
Dim varDaten2 As Variant
Dim varDaten3 As Variant
Dim varDaten4 As Variant
varDaten1 = Sheets("Tabelle1").Range("B1:B" & Sheets("Tabelle1").Cells(Rows.Count, 2).End( _
_
xlUp).Row)
varDaten2 = Sheets("Tabelle2").Range("B1:B" & Sheets("Tabelle2").Cells(Rows.Count, 2).End( _
_
xlUp).Row)
varDaten3 = Sheets("Tabelle3").Range("B1:B" & Sheets("Tabelle3").Cells(Rows.Count, 2).End( _
_
xlUp).Row)
varDaten4 = Sheets("Tabelle4").Range("B1:B" & Sheets("Tabelle4").Cells(Rows.Count, 2).End( _
_
xlUp).Row)
With ComboBox1
.List = varDaten1
End With
With ComboBox2
.List = varDaten2
End With
With ComboBox3
.List = varDaten3
End With
With ComboBox4
.List = varDaten4
End With
End Sub