ich habe eine UF mit Listbox und Textboxes.
Was nicht funktioniert ist das Ändern eines Datensatzes.
Könnt ihr bitte mal den Code ansehen und prüfen, was hier falsch ist.
anbei den Code der UF:
Private Sub UserForm_Initialize()
With Sheets("Buchen")
With ListBox1
.Clear
.ColumnCount = 6
.ColumnWidths = "3,0 cm;4,5 cm;4,5 cm;3,0 cm;3,0 cm;3,0 cm"
ListBox1.RowSource = "Buchen!B9:G" & .Cells(Rows.Count, 2).End(xlUp).Row
End With
End With
With Sheets("Hilfstabelle")
ComboBox1.RowSource = "Hilfstabelle!B2:B" & .Cells(Rows.Count, 2).End(xlUp).Row
End With
End Sub
Private Sub ListBox1_Click()
'klick = ListBox1.ListIndex
With ListBox1
UF_Buchungen.TextBox1 = .List(.ListIndex, 0)
UF_Buchungen.TextBox2 = .List(.ListIndex, 1)
UF_Buchungen.ComboBox1 = .List(.ListIndex, 2)
UF_Buchungen.TextBox4 = .List(.ListIndex, 3)
UF_Buchungen.TextBox5 = .List(.ListIndex, 4)
End With
End Sub
'Daten hinzufügen
Private Sub CommandButton1_Click()
With Worksheets("Buchen")
.Cells(.Cells(Rows.Count, 2).End(xlUp).Row + 1, 2) = Format(TextBox1.Value, "dd.mm.yyyy")
.Cells(.Cells(Rows.Count, 3).End(xlUp).Row + 1, 3) = TextBox2.Value
.Cells(.Cells(Rows.Count, 4).End(xlUp).Row + 1, 4) = ComboBox1.Value
.Cells(.Cells(Rows.Count, 5).End(xlUp).Row + 1, 5) = CDbl(TextBox4)
.Cells(.Cells(Rows.Count, 6).End(xlUp).Row + 1, 6) = CDbl(TextBox5)
.Cells(.Cells(Rows.Count, 7).End(xlUp).Row + 1, 7).FormulaR1C1 = "=SUM(R[-1]C[0]+R[0]C[-2]-R[0] _
C[-1])"
End With
''zeigt Bestand in Textbox6 an
'TextBox6.Value = Cells(Zeile6 + 1, 7)
End Sub
'Daten ändern
Private Sub CommandButton4_Click()
Dim lastRow As Long
lastRow = Range("B65536").End(xlUp).Row
With Range("Buchen!B9:G" & lastRow)
Me.Tag = "1"
.Cells(ListBox1.ListIndex + 1, 1).Value = TextBox1.Value
.Cells(ListBox1.ListIndex + 1, 2).Value = TextBox2.Value
.Cells(ListBox1.ListIndex + 1, 3).Value = ComboBox1.Value
.Cells(ListBox1.ListIndex + 1, 4).Value = CDbl(TextBox4)
.Cells(ListBox1.ListIndex + 1, 5).Value = CDbl(TextBox5)
Me.Tag = ""
End With
UserForm_Initialize
End Sub
Die Änderung funktioniert leider nicht. Was ist bitte falsch?Die Listbox fülle ich mit rowsource, da dadurch die Formate der Tabelle
angezeigt werden.
Besten Dank für eure Hilfe.
Gruss
Peter