Calculate time difference from barcode scans in Excel



Calculate time difference from barcode scans in excel. Track how long time is spent by subtracting the times generated by barcode scans. Learn how to calculate the time difference between to time scans.
Check out my online courses

code for sheet
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range(“A2”)) Is Nothing Then
Call access
Application.EnableEvents = True
End If
End Sub

Sub access()
Dim barcode As String
Dim rng As Range
Dim rownumber As Long
Dim cell
Dim Total As Double
Dim Timein As Date
Dim Timeout As Date

‘barcode = Worksheets(“Attendance”).Cells(2, 1)
barcode = ActiveSheet.Cells(2, 1)
If barcode not equal to “” Then
Set rng = ActiveSheet.Columns(“a:a”).Find(What:=barcode, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If rng Is Nothing Then
restart:
ActiveSheet.Columns(“a:a”).Find(“”).Select
ActiveCell.Value = barcode
ActiveCell.NumberFormat = “@”
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = Date & ” ” & Time
ActiveCell.NumberFormat = “d/m/yyyy h:mm AM/PM”
ActiveSheet.Cells(2, 1) = “”
GoTo ende
Else
‘rng.Select
rownumber = rng.Row
If Cells(rownumber, 4) not equal to “” Then GoTo restart
ActiveSheet.Cells(rownumber, 1).Select
ActiveCell.Offset(0, 3).Select
ActiveCell.Value = Date & ” ” & Time
ActiveCell.NumberFormat = “m/d/yyyy h:mm AM/PM”
Timein = CDate(Cells(rownumber, 3).Value)
Timeout = CDate(Cells(rownumber, 4).Value)
Total = TimeValue(Timeout) – TimeValue(Timein)
Debug.Print Total
Debug.Print Format(Total, “hh:mm:ss”)
Cells(rownumber, 5).NumberFormat = “hh:mm:ss”
Cells(rownumber, 5).Value = Total
Debug.Print “Number of hours = ” & Total * 24
ActiveSheet.Cells(2, 2) = “”
End If
ActiveSheet.Cells(2, 1) = “”
End If
ende:
ActiveSheet.Cells(2, 1).Select
End Sub

For more help visit my website or email me at easyexcelanswers@gmail.com.

Contact me regarding customizing this template for your needs.

Click for online Excel Consulting

I am able to provide online help on your computer at a reasonable rate.

Check out my next one-hour Excel Webinar

I use a Blue condensor Microphone to record my videos, here is the link

Check out Crowdcast for creating your webinars

If you need to buy Office 2019 follow

I use Tube Buddy to help promote my videos
Check them out

Follow me on Facebook

TWEET THIS VIDEO

Follow me on twitter
easyexcelanswers

IG @barbhendersonconsulting

You can help and generate a translation to you own language

*this description may contain affiliate links. When you click them, I may receive a small commission at no extra cost to you. I only recommend products and services that I’ve used or have experience with.

Watch more new videos about Excel Office | Synthesized by Mindovermetal English

5/5 - (1 bình chọn)

Bài viết liên quan

Theo dõi
Thông báo của
guest
6 Comments
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất
Phản hồi nội tuyến
Xem tất cả bình luận
Barb Henderson

Thank you so much for watching my video. I am not allowed to include square brackets in the description of my video therefore, <> has been replaced with the words "not equal to" and < is replaced with the words "less than"

Contrapunctus1750

Great video! I've tried to implement the code, but it only works for the first time a particular person scans in and out. After that, every time that person's code is scanned, it shows up under "Time in." I'm wracking my brain trying to figure out why…

yokepeng

Hi, Barb! Thanks for the video, it really helping much.

While I faced some question in this coding.

I found it could not scan to the 2nd out as the line for "If Cells(rownumber,4) is not equal to blank".

Eg, Amritpal Glass was not able to to check out 2nd time and will directly go to 3rd time check in. I think the line of code that i mentioned above, will keep on bring back the rownumber goto restart as the first check out for Amritpal Glass is not blank.

May i know what i could do to resolve this?

aieswwarya sivaraman

Ma'am i have tried this and it is working wonderfully but after several days i closed and open, the name function does not appear automatically when key in id number. May I know anything i could do on in order for it to function well for name part?

pratiksha ronghe

Hello Maa'm,
Can you make video on how to avoid duplicate ID with allowing duplicate ID after 10min. Reply soon.

Alex

Oh yes! I was waiting for something like this! Thank you very much Barb! I love your videos!