VBA Punch Clock and Calculating Hours worked based on Start Time, End Time and Deduct the Lunch break

jmastermc

New Member
Joined
May 5, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello, I am completely noob at this and reading through these forums. Just learned about VBA and how to create a button for similar need.

I got the following code from another discussion on here. I would like the same date stay in the same row to complete a days worth of punches. and then at the end end add up their hours work for the day deducting the lunch in/out time, if that makes sense?

I would like to make the info unchangeable aside from the timestamp button recording everything to avoid the employees from tampering with their edits.

Is that possible? this is the code I was playing with:

Sub Timestamp()
Dim yourelate As String
Dim LastRow As Object
yourelate = Application.InputBox("Please enter employee ID #", "Employee ID", Type:=1)
Set LastRow = Sheets("Sheet1").Range("A65536").End(xlUp)

With LastRow
.Offset(1, 0) = yourelate
.Offset(1, 2) = yourelate
.Offset(1, 2) = Date
.Offset(1, 3) = Time
End With

End Sub

This is what I left off at and can't figure out how to move forward:

Sub Timestamp()
Dim yourelate As String
Dim LastRow As Object
yourelate = Application.InputBox("Please enter employee ID #", "Employee ID", Type:=1)
ontime = Application.InputBox("Please enter Entry Type", "General", Type:=2)
Set LastRow = Sheets("Sheet1").Range("A65536").End(xlUp)

With LastRow
.Offset(1, 0) = yourelate
.Offset(1, 1) = ontime
.Offset(1, 2) = Date
.Offset(1, 3) = Time
End With

End Sub

I'm really new to all this and just staring at the codes and adding and editing information until it functions in how I'm envisioning through trial and error. I'm not well versed in the lingo but a quick study and google anything I don't know but figured asking will be faster.

I appreciate any help.

Thank you!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

jmastermc

New Member
Joined
May 5, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Update on Code in VBA. I'm unsure how to record the 2nd time stamp without the employee ID application input box. I just need the time recorded at that point on offset(1, 3) = Time

Sub Timestamp()
Dim yourelate As String
Dim LastRow As Object
yourelate = Application.InputBox("Please enter employee ID #", "Employee ID", Type:=1)
Set LastRow = Sheets("Sheet1").Range("A65536").End(xlUp)

With LastRow
.Offset(1, 0) = yourelate
.Offset(1, 1) = Date
.Offset(1, 2) = Time
.Offset(1, 3) = Time
End With

End Sub

Kind of have a mini sample of what I'm trialing to give context

1620244705947.png
 

Forum statistics

Threads
1,143,839
Messages
5,721,096
Members
422,339
Latest member
SHIVATVM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top