AW: Combobox und Textboxen
26.02.2015 13:59:49
Vojnic
Hallo nochmal und danke für deine Antwort. Habe dann folgendes nach ein wenig experimentieren zusammengebastelt:
Private Sub ComboBox1_Click()
If ComboBox1.ListIndex > 0 Then
TextBox1 = Cells(ComboBox1.ListIndex + 2, 2)
TextBox2 = Cells(ComboBox1.ListIndex + 2, 3)
TextBox3 = Cells(ComboBox1.ListIndex + 2, 4)
TextBox4 = Cells(ComboBox1.ListIndex + 2, 5)
TextBox5 = Cells(ComboBox1.ListIndex + 2, 6)
TextBox6 = Cells(ComboBox1.ListIndex + 2, 7)
Else
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub CommandButton1_Click()
Dim xZeile As Long
If TextBox1 = "" Then Exit Sub
If ComboBox1.ListIndex = 0 Then
xZeile = [A65536].End(xlUp).Row + 1
Else
xZeile = ComboBox1.ListIndex + 2
End If
Cells(xZeile, 2) = TextBox1
Cells(xZeile, 3) = TextBox2
Cells(xZeile, 4) = TextBox3
Cells(xZeile, 5) = TextBox4
Cells(xZeile, 6) = TextBox5
Cells(xZeile, 7) = TextBox6
Columns("A:F").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
An sich klappt es ganz gut. Nur wenn ich die die Userform und den ersten Datensatz aufrufe erscheint nichts in den Textfeldern. Beim zweiten Datensatz fehlt der erste Wert in der Textbox1. Erst bei dem dritten Datensatz wird alles vollständig in den Textboxen angezeigt. Sobald ich aber wieder auf den zweiten Datensatz zurückgehe ist alles wieder vollständig. Der erste Datensatz fehlt aber weiterhin in den Textboxen. Leider ist meine Kenntnis in VBA beschränkt. Ich denke die Lösung wäre für einen Profi einfach.
Für die Uhrzeiteingabe habe ich eine Lösung gefunden die in der Tabelle die 4stellige Zahl in Uhrzeit umformatiert.
Danke schon mal im Voraus