könnte so gehen...
08.02.2015 08:49:29
Tino
Hallo,
versuch es mal so.
Private Sub CommandButton3_Click()
Dim letzte_Zeile As Long
Dim i%
For i = 1 To 8
If Me("TextBox" & i) = "" Or ComboBox1.Text = "" Then
MsgBox "Alle Felder ausfüllen!"
Exit Sub
End If
Next i
If FindEintrag Then
MsgBox "Der Name '" & ComboBox1.Value & " " & TextBox1 & "'ist schon vorhanden!"
Exit Sub
End If
With Worksheets("Daten")
' Datensatz neu speichern
letzte_Zeile = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
.Cells(letzte_Zeile, 1) = Application.WorksheetFunction.Max(.Columns(1)) + 1
.Cells(letzte_Zeile, 2) = TextBox1.Text
.Cells(letzte_Zeile, 3) = ComboBox1.Text
.Cells(letzte_Zeile, 4) = TextBox2
.Cells(letzte_Zeile, 5) = TextBox3.Text
.Cells(letzte_Zeile, 6) = TextBox4.Text
.Cells(letzte_Zeile, 7) = TextBox5.Text
.Cells(letzte_Zeile, 8) = TextBox6.Text
.Cells(letzte_Zeile, 9) = TextBox7.Text
.Cells(letzte_Zeile, 10) = TextBox8.Text
End With
ClearAll
UserForm_Initialize
ComboBox1.SetFocus
End Sub
Function FindEintrag() As Boolean
Dim rng As Range, sErste$
Set rng = Columns(3).Find(What:=ComboBox1.Value, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If rng Is Nothing Then Exit Function
If Cells(rng.Row, 2).Value = TextBox1 Then
FindEintrag = True
Exit Function
End If
sErste = rng.Address
Set rng = Columns(3).FindNext(rng)
Do While sErste rng.Address
If Cells(rng.Row, 2).Value = TextBox1 Then
FindEintrag = True
Exit Function
End If
Set rng = Columns(3).FindNext(rng)
Loop
End Function
Gruß Tino