Good Day People, im kinda new to VBA.
Im trying to make a time and attandance. Im actually pretty far, but unforntuanly i ran into a problem.
I use 2 Userforms. One where you get with your id to your sheet and can then clock in or clock out on the userform2.
When they clocked in or clocked it, it goes back to the first form. Unfornuatly the form doesnt work then anymore. I tried loading, hide, show, exit sub, searched the internet but cant find a solution.
Maybe im doing something wrong, that the modul / Userform doesnt work anymore.
Im thankfull for any help.
Dont mind Names of Strings and stuff, its just a test before i do the real one.
Im using the modulobject for the code. Looks better for me So im refering in Userform1 Objects to a sub in the modullib.
Modul1:
Function DoesSheetExists(sh As String) As Boolean
Dim ws As Worksheet
On Error Resume Next
Set ws = ThisWorkbook.Sheets(sh)
On Error GoTo 0
If Not ws Is Nothing Then DoesSheetExists = True
End Function
Sub ScanID()
Dim MitarbeiterWS As Worksheet
Dim MitarbeiterID As Range
Dim MitarbeiterIDstring As String
Dim MitarbeiterName As String
ThisWorkbook.Sheets("MitarbeiterID").Activate
MitarbeiterIDstring = UserForm1.TextBox1.Value
Set MitarbeiterID = Range("A1:A30").Find(What:=MitarbeiterIDstring)
If Not MitarbeiterID Is Nothing Then
MitarbeiterName = MitarbeiterID.Offset(, 1).Value
UserForm1.Label1 = MitarbeiterName
If Not DoesSheetExists(MitarbeiterName) Then
If Not MitarbeiterName = "" Then
Sheets("Example").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = MitarbeiterName
Unload UserForm1
UserForm2.Show
MitarbeiterID.Select
Else
End If
Else
ThisWorkbook.Sheets(MitarbeiterName).Activate
Unload UserForm1
UserForm2.Show
End If
Else
End If
End Sub
Modul2
Sub Eincloggen()
Dim Einspalte As Range
Set Einspalte = Range("A1").End(xlDown)
'wenn zum ersten mal eingeclockt
If Einspalte.Offset(, 1).Value = "" Then
If Einspalte.Value = "Clocked In" Then
Einspalte.Offset(1, 0).Value = Now
Else
MsgBox "Erst Raus"
End If
Else
Einspalte.Offset(1, 0).Value = Now
Unload UserForm2
UserForm2.Hide
UserForm1.Show
End If
End Sub
Sub Auscloggen()
Dim Einspalte As Range
Dim Ausspalte As Range
Dim Pausenspalte As Range
Dim Stundenspalte As Range
Set Einspalte = Range("A1").End(xlDown)
Set Ausspalte = Range("B1").End(xlDown)
Set Pausenspalte = Range("C1").End(xlDown)
Set Stundenspalte = Range("D1").End(xlDown)
If Ausspalte.Offset(1, -1).Value = "" Then
MsgBox "Erst Rein"
Else
Ausspalte.Offset(1, 0).Value = Now
If Not Ausspalte.Offset(1, 0).Value = "" Then
Stundenspalte.Offset(1, 0).Value = (Ausspalte.Offset(1, 0).Value) - (Einspalte.Value)
Stundenspalte.Offset(1, 0).NumberFormat = "hh:mm"
Unload UserForm2
UserForm2.Hide
UserForm1.Show
End If
End If
End Sub