ich habe eine VBA Anweisung von Klaus Dieter Oppermann im Netzt gefunden und meinen Bedürfnissen etwas angepasst.
Vielleicht kann mir jemand beim ändern helfen.
Das Makro schreibt Werte aus Textboxen immer in die erste gefundene leere Zeile.
Da in Spalte A eine laufende Nummer vergeben wird möchte ich gern, dass beim Aufruf der UF in meiner Textbox1 die gefundenen Zahl der letzten Zeile in Spalte A +1 automatisch eingetragen wird.
Option Explicit
Private Sub commandButton1_Click()
Dim zelle As Object
Dim ersteAdresse As String
Dim we As String
Dim zi As Integer
we = TextBox1.Text
With Worksheets(1).Range("a1:a50")
Set zelle = .Find(we, LookIn:=xlValues)
If Not zelle Is Nothing Then
ersteAdresse = zelle.Address
zi = zelle.Row
Rows(zi + 1).Insert Shift:=xlDown
Cells(zi + 1, 2) = TextBox2.Text
Cells(zi + 1, 3) = TextBox3.Text
Cells(zi + 1, 4) = TextBox4.Text
Cells(zi + 1, 5) = TextBox5.Text
Cells(zi + 1, 6) = TextBox6.Text
Cells(zi + 1, 7) = TextBox7.Text
Cells(zi + 1, 8) = TextBox8.Text
Cells(zi + 1, 9) = TextBox9.Text
Cells(zi + 1, 10) = TextBox10.Text
Cells(zi + 1, 11) = TextBox11.Text
End If
End With
If zi > 1 Then Exit Sub
Cells(Range("A65536").End(xlUp).Row + 1, 1) = TextBox1.Text
Cells(Range("A65536").End(xlUp).Row, 2) = TextBox2.Text
Cells(Range("A65536").End(xlUp).Row, 3) = TextBox3.Text
Cells(Range("A65536").End(xlUp).Row, 4) = TextBox4.Text
Cells(Range("A65536").End(xlUp).Row, 5) = TextBox5.Text
Cells(Range("A65536").End(xlUp).Row, 6) = TextBox6.Text
Cells(Range("A65536").End(xlUp).Row, 7) = TextBox7.Text
Cells(Range("A65536").End(xlUp).Row, 8) = TextBox8.Text
Cells(Range("A65536").End(xlUp).Row, 9) = TextBox9.Text
Cells(Range("A65536").End(xlUp).Row, 10) = TextBox10.Text
Cells(Range("A65536").End(xlUp).Row, 11) = TextBox11.Text
UserForm1.TextBox1 = ""
UserForm1.TextBox2 = ""
UserForm1.TextBox3 = ""
UserForm1.TextBox4 = ""
UserForm1.TextBox5 = ""
UserForm1.TextBox6 = ""
UserForm1.TextBox7 = ""
UserForm1.TextBox8 = ""
UserForm1.TextBox9 = ""
UserForm1.TextBox10 = ""
UserForm1.TextBox11 = ""
End Sub
Private Sub commandButton2_Click()
UserForm1.Hide
End Sub