ich habe ein User Form, der im Tabellenblatt 2022 in der Zeile 1 das Datum sucht. Ich möchte, das nicht komplett die erste Zeile sucht, nur von B1 bis NB1.
der hintergrund dafür ist, dass der Mitarbeiter im Jahr 2023 ein neues Tabellenblatt nimmt ( das erstelle dann ich ). Oder gibt es eine Möglichkeit, dass im User Form es nicht zu lässt Daten das die Daten von 2023 nicht in den Tabellenblatt 2022 kommen. ( z.b. Meldung. "melde dich an Admin das Daten in 2023 gespeichert werden darf )
Danke euch
Private Sub Cmd_Speichern_Click()
Dim crt As Control
Dim intCol As Integer
Dim lngDatum As Long
lngDatum = CDate(TextBox2_datum)
Application.ScreenUpdating = False
With Workbooks("report.xlsm").Sheets("2022")
If Not IsError(Application.Match(lngDatum, .Rows(1), 0)) Then
intCol = Application.Match(lngDatum, .Rows(1), 0)
.Cells(2, intCol).Value = TextBox1_user.Value
.Cells(4, intCol).Value = Txt_St.alue
.Cells(3, intCol).Value = Format(CDate(TextBox3_zeit.Value), "hh:mm")
.Cells(5, intCol).Value = Txt_Sp2.Value
If IsNumeric(TextBox28.Text) Then .Cells(28, intCol).Value = CDbl(TextBox28.Text) / 100
If IsNumeric(TextBox29.Text) Then .Cells(29, intCol).Value = CDbl(TextBox29.Text) / 100
If IsNumeric(TextBox30.Text) Then .Cells(30, intCol).Value = CDbl(TextBox30.Text) / 100
.Cells(31, intCol).Value = Txt_Arbeitszeit_früh.Value
Else
MsgBox "falsches Datum"
With TextBox2_datum
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
Exit Sub
End If
End With
MsgBox "Daten wurden Erfolgreich in die Datenbank gespeichert !!!", , "Rückantwort -> Datenbank"
With Workbooks("report.xlsm")
.Save
'.Close
End With
Application.ScreenUpdating = True
For Each crt In Me.Controls
Select Case TypeName(crt)
Case "TextBox"
crt.Value = ""
Case Else
End Select
Next
End Sub
Private Sub UserForm_Initialize()
Const STARTUP_MANUAL As Long = 0
StartUpPosition = STARTUP_MANUAL
Top = 20 'anpassen...
Left = 290 'anpassen...
TextBox1_user.Value = Application.UserName
TextBox2_datum.Value = Date
TextBox3_zeit.Value = Time