' Funny message generator
Function GetFunnyMessage(action As String) As String
Dim messagesIn As Variant
Dim messagesOut As Variant
Dim index As Integer
messagesIn = Array( _
"Time In complete! Let's survive the day ???", _
"Back to the grind! ????", _
"Clocked in! The coffee better be ready ??", _
"Welcome back to your second home ????", _
"Here we go again... ?? Good luck!" _
)
messagesOut = Array( _
"Work complete! Go home and chill ????", _
"Bye Felicia! ???????", _
"Logging out like a boss ?????", _
"Time out! Don’t forget your snacks! ????", _
"You're freeeeeee! ?????" _
)
Randomize
index = Int(Rnd() * UBound(messagesIn) + 1)
If action = "in" Then
GetFunnyMessage = messagesIn(index)
Else
GetFunnyMessage = messagesOut(index)
End If
End Function
' Time In
Sub TimeInOnly()
Dim wsRecord As Worksheet
Dim employeeName As String
Dim currentTime As String
Dim currentDate As String
Dim lastRow As Long
Dim msg As String
Set wsRecord = ThisWorkbook.Sheets("Record")
employeeName = InputBox("Enter your name to Time In:", "Time In")
If employeeName = "" Then Exit Sub
currentTime = Format(Now, "hh:mm:ss AM/PM")
currentDate = Format(Now, "dd-mmm-yy")
lastRow = wsRecord.Cells(wsRecord.Rows.Count, "B").End(xlUp).Row + 1
' Record log
wsRecord.Cells(lastRow, "B").Value = employeeName
wsRecord.Cells(lastRow, "C").Value = currentDate
wsRecord.Cells(lastRow, "D").Value = currentTime
' Reflect in active sheet cell C6
ThisWorkbook.ActiveSheet.Range("C6").Value = currentTime
msg = GetFunnyMessage("in")
MsgBox "? " & employeeName & " clocked in at " & currentTime & vbCrLf & msg,
vbInformation, "Time In"
End Sub
' Time Out
Sub TimeOutOnly()
Dim wsRecord As Worksheet
Dim employeeName As String
Dim currentTime As String
Dim lastRow As Long
Dim msg As String
Set wsRecord = ThisWorkbook.Sheets("Record")
employeeName = InputBox("Enter your name to Time Out:", "Time Out")
If employeeName = "" Then Exit Sub
currentTime = Format(Now, "hh:mm:ss AM/PM")
lastRow = wsRecord.Cells(wsRecord.Rows.Count, "B").End(xlUp).Row
Do While wsRecord.Cells(lastRow, "B").Value <> employeeName And lastRow > 1
lastRow = lastRow - 1
Loop
If wsRecord.Cells(lastRow, "B").Value = employeeName Then
wsRecord.Cells(lastRow, "E").Value = currentTime
' Reflect in active sheet cell C7
ThisWorkbook.ActiveSheet.Range("C7").Value = currentTime
msg = GetFunnyMessage("out")
MsgBox "?? " & employeeName & " clocked out at " & currentTime & vbCrLf &
msg, vbInformation, "Time Out"
Else
MsgBox "?? Name not found in Record sheet.", vbExclamation, "Time Out
Error"
End If
End Sub