habe mir eine Userform aufgebaut, wo ich noch folgendes brauche:
sobald ich die DATEN aus den Textboxen in die Zellen schreibe, soll nun noch dem Datensatz ein Nr/ID zugewiesen werden. (in der selben Zeile)
Sollte später aus den eingegeben Daten ein Datensatz gelöscht werden, darf die Nr/ID nicht nochmals auftauchen.
verwendetes Makro Datensatz schreiben:
Private Sub CommandButton2_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 + 1
End If
Worksheets("Kunden").Visible = True
Worksheets("Kunden").Unprotect
Cells(xZeile, 1) = TextBox1
Cells(xZeile, 2) = TextBox2
Cells(xZeile, 3) = TextBox3
Cells(xZeile, 4) = TextBox4
Cells(xZeile, 5) = TextBox5
Cells(xZeile, 6) = TextBox6
Cells(xZeile, 7) = TextBox7
Cells(xZeile, 8) = TextBox8
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
Columns("A:I").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
UserForm_Initialize
Worksheets("Kunden").Protect
End Sub
Die Nr/Id muss in Spalte I (9)Und Makro:
Private Sub UserForm_Initialize()
Dim aRow, i As Long
Application.EnableEvents = False
ComboBox1.Clear
aRow = [A65536].End(xlUp).Row
ComboBox1.AddItem "neue Person hinzufügen"
For i = 2 To aRow
ComboBox1.AddItem Cells(i, 1) & ", " & Cells(i, 2)
Next i
ComboBox1.ListIndex = 0
Application.EnableEvents = True
End Sub
Makro zum löschen:Private Sub CommandButton1_Click()
Worksheets("Kunden").Visible = True
Worksheets("Kunden").Unprotect
If ComboBox1.ListIndex > 0 Then
Rows(ComboBox1.ListIndex + 1).Delete
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
UserForm_Initialize
Worksheets("Kunden").Protect
End If
End Sub
Danke für jegliche Hilfe.