AW: User Form eintag in Tabelle
24.07.2019 22:00:13
Matthias
Moin!
Dann einfach mal so probieren. Habe da den Teil für das zweite Blatt nur darunter kopiert. Für 2 Blätter reicht das auch so. Bei mehr würde ich eine Schleife basteln - da hatte ich in anbetracht der Hitze grad keine Lust. :-)
Private Sub cmd_speichern_Click()
Dim ws As Worksheet
Dim intLZ As Long, zeile As Long
Dim Eingabe
If Me.txt_Name "" And Me.Txt_Personalnummer "" And Me.Txt_Geburtsdatum "" Then
Set ws = ThisWorkbook.Sheets("Planer") 'hier stand mal Mitarbeiter
intLZ = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
For zeile = 2 To inLZ 'er sucht in der 2. Zeile, ggf. die 2 in eine andere Startzeile _
_
ändern
If VBA.StrComp(Me.txt_Name, ws.Cells(zeile, 3)) = -1 Then
ws.Rows(zeile).Insert Shift:=xlDown 'Zeile einfügen
Exit For
End If
Next
'sollte der Wert nicht gefunden werden, wird unten angehangen
With Me
ws.Cells(zeile, 2).Value = .Txt_Personalnummer
'.Txt_Personalnummer = ""
ws.Cells(zeile, 3).Value = .txt_Name
'.Txt_Name = ""
ws.Cells(zeile, 4).Value = .Txt_Eintritt
'.Txt_Eintritt = ""
ws.Cells(zeile, 6).Value = .Txt_Geburtsdatum
'.Txt_Geburtsdatum = ""
ws.Cells(zeile, 8).Value = .ListBox1
'.ListBox1 = ""
ws.Cells(zeile, 9).Value = .TxtAbt
'.TxtAbt = ""
ws.Cells(zeile, 10).Value = .txt_Telefon
'.Txt_Telefon = ""
ws.Cells(zeile, 11).Value = .txt_Handy
'.Txt_Handy = ""
ws.Cells(zeile, 12).Value = .txt_info
'.Txt_Info = ""
If .Kinder.Value = True Then ws.Cells(zeile, 13).Value = "Ja"
ws.Cells(zeile, 17).Value = .txt_Urlaub
'.Txt_Urlaub = ""
End With
Set ws = ThisWorkbook.Sheets("Mitarbeiter") 'hier stand mal Mitarbeiter
intLZ = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
For zeile = 2 To inLZ 'er sucht in der 2. Zeile, ggf. die 2 in eine andere Startzeile _
_
ändern
If VBA.StrComp(Me.txt_Name, ws.Cells(zeile, 3)) = -1 Then
ws.Rows(zeile).Insert Shift:=xlDown 'Zeile einfügen
Exit For
End If
Next
'sollte der Wert nicht gefunden werden, wird unten angehangen
With Me
ws.Cells(zeile, 2).Value = .Txt_Personalnummer
'.Txt_Personalnummer = ""
ws.Cells(zeile, 3).Value = .txt_Name
'.Txt_Name = ""
ws.Cells(zeile, 4).Value = .Txt_Eintritt
'.Txt_Eintritt = ""
ws.Cells(zeile, 6).Value = .Txt_Geburtsdatum
'.Txt_Geburtsdatum = ""
ws.Cells(zeile, 8).Value = .ListBox1
'.ListBox1 = ""
ws.Cells(zeile, 9).Value = .TxtAbt
'.TxtAbt = ""
ws.Cells(zeile, 10).Value = .txt_Telefon
'.Txt_Telefon = ""
ws.Cells(zeile, 11).Value = .txt_Handy
'.Txt_Handy = ""
ws.Cells(zeile, 12).Value = .txt_info
'.Txt_Info = ""
If .Kinder.Value = True Then ws.Cells(zeile, 13).Value = "Ja"
ws.Cells(zeile, 17).Value = .txt_Urlaub
'.Txt_Urlaub = ""
End With
Set ws = Nothing
Else
MsgBox "Bitte alle Felder ausfüllen!!!", , " Fehler !!!"
Me.txt_Name.SetFocus
Exit Sub
End If
MsgBox "Daten wurden gespeichert !!!"
End Sub
VG