Scan barcode to excel with date & time stamp in & out.

qpywsqp

New Member
Joined
Dec 2, 2012
Messages
26
Hi all. I have research around the internet and finally found out Macro able to solve my issue. But im totally not a programmer. Hopefully someone can help me on this.

I will scan QR Code with a scanner to cell A1 and wanted cell C1 to have date and time stamp for IN. When Scanner scan the same QR Code, D1 will have date and time stamp for out. If repeat third time scanning the same QR code after a few scanning, it will appear on next row. Which means A8 with the code and C8 with date and time stamp for IN again.

Is that possible to done with Macro?
 
ShinoHei,

Your workbook contains 2 worksheets.

StaffList, with data in columns A, and B.

A1 = ID
B1 = Name

TimeLog, with titles in row 1.

Which worksheet will have the Worksheet_Change event macro code?

Please explain in detail where in which worksheet name, column you will be manually entering information?
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
hiker95,

The StaffList worksheet will contain all barcode ID and their corresponding Name.
The TimeLog worksheet will contain the Worksheet_Change event macro code.

Data will be entered manually or through barcode scanner into A2 of TimeLog
B2 will be populated with VLOOKUP of A2 in worksheet StaffList to return name corresponding to the barcode ID
Code:
=IF(A2<>"",VLOOKUP(A2,StaffList!$A$2:$B$1000,2,FALSE),"")
The Worksheet_Change event macro code will populate TimeIn and TimeOut Columns

I have used the code from post #18

Let me know if you need more info, thanks!
 
Upvote 0
ShinoHei,

In a copy of your workbook, try the following Worksheet_Change event macro code in worksheet TimeLog.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' hiker95, 03/01/2018, ME672492
If Intersect(Target, Range("A2:A3000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim lc As Long, fr As Long, n As Long, nr As Long
With Application
  .EnableEvents = False
  .ScreenUpdating = False
  n = Application.CountIf(Columns(1), Cells(Target.Row, 1))
  If n = 1 Then
    lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
    If lc = 2 Then
      Cells(Target.Row, lc + 2) = Now
    ElseIf lc > 2 Then
      Cells(Target.Row, lc + 1) = Now
    End If
  Else
    fr = 0
    On Error Resume Next
    fr = Application.Match(Cells(Target.Row, 1), Columns(1), 0)
    On Error GoTo 0
    If fr > 0 Then
      lc = Cells(fr, Columns.Count).End(xlToLeft).Column
      If lc = 1 Then
        Cells(fr, lc + 2) = Now
      ElseIf lc > 2 Then
        Cells(fr, lc + 1) = Now
      End If
      Target.ClearContents
    End If
  End If
  On Error Resume Next
  Me.Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  On Error GoTo 0
  nr = Me.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
  Me.Cells(nr, 1).Select
  .EnableEvents = True
  .ScreenUpdating = True
End With
ThisWorkbook.Save
End Sub
 
Upvote 0
ShinoHei,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.

hiker95,

To add to the functionality of this workbook, is it complicated to implement a function where it will will create a new worksheet when the day the data was enter is different from the worksheet name?

For example, worksheet StaffList remains the same, while TimeLog is changed to TimeLog_Template. A new worksheet Feb-28-2018 will be created after TimeLog_Template. Now when the data is entered on March 1, 2018, it will compare the current date with the worksheet name and when different, duplicate TimeLog_Template to the end named Mar-01-2018 as well as put in the time stamp, when data is entered on March 2, it will again duplicate TimeLog_Template to the end of the workbook and named Mar-02-2018 and the same process happen on March 3 and March 4 and so on.

Is something like this possible?

Thank you so much for your efforts!!
 
Upvote 0
To add to the functionality of this workbook, is it complicated to implement a function where it will will create a new worksheet when the day the data was enter is different from the worksheet name?

For example, worksheet StaffList remains the same, while TimeLog is changed to TimeLog_Template. A new worksheet Feb-28-2018 will be created after TimeLog_Template. Now when the data is entered on March 1, 2018, it will compare the current date with the worksheet name and when different, duplicate TimeLog_Template to the end named Mar-01-2018 as well as put in the time stamp, when data is entered on March 2, it will again duplicate TimeLog_Template to the end of the workbook and named Mar-02-2018 and the same process happen on March 3 and March 4 and so on.

ShinoHei,

I do not understand your latest request, and, I can not see the logic for what you are now asking.

Maybe someone else on MrExcel will be able to assist.
 
Last edited:
Upvote 0
qpywsqp,

When you begin to scan in delegates for the first time, the active cell should be cell A2.

If the active cell, for some reason, is not cell A2, then the macro will move the delegate to cell A2...

And, then if you move the active cell below the last recorded delegate (by 1 or more rows) the macro will remove the blank rows in column A.

The macro will make the active cell, the next available blank cell in column A.



Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Select the worksheet in which your code is to run
3. Right click on the sheet tab and choose View Code, to open the Visual Basic Editor
4. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
5. Press the keys ALT + Q to exit the Editor, and return to Excel


Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' hiker95, 12/18/2012
' http://www.mrexcel.com/forum/excel-questions/672492-scan-barcode-excel-date-time-stamp-out.html
If Intersect(Target, Range("A2:A3000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim lc As Long, fr As Long, n As Long, nr As Long
With Application
  .EnableEvents = False
  .ScreenUpdating = False
  n = Application.CountIf(Columns(1), Cells(Target.Row, 1))
  If n = 1 Then
    lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
    If lc = 1 Then
      Cells(Target.Row, lc + 2) = Format(Now, "m/d/yyyy h:mm")
    ElseIf lc > 2 Then
      Cells(Target.Row, lc + 1) = Format(Now, "m/d/yyyy h:mm")
    End If
  Else
    fr = 0
    On Error Resume Next
    fr = Application.Match(Cells(Target.Row, 1), Columns(1), 0)
    On Error GoTo 0
    If fr > 0 Then
      lc = Cells(fr, Columns.Count).End(xlToLeft).Column
      If lc = 1 Then
        Cells(fr, lc + 2) = Format(Now, "m/d/yyyy h:mm")
      ElseIf lc > 2 Then
        Cells(fr, lc + 1) = Format(Now, "m/d/yyyy h:mm")
      End If
      Target.ClearContents
    End If
  End If
  On Error Resume Next
  Me.Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  On Error GoTo 0
  nr = Me.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
  Me.Cells(nr, 1).Select
  .EnableEvents = True
  .ScreenUpdating = True
End With
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Please test the new Worksheet_Change event in the office before going into the field.


Hi hikeres95,

this was very helpful for me....thank you,
but i really need help if the condition was little bit different :
what if after record of JACKY was filled in time first out colum . then the second time in will be in new record in colum A
so the same name will created after time out created and QTY was done input.

please help me .....
 
Upvote 0
Hi hiker95,

the excecl sample will be like :

Capture.jpg
[/URL][/IMG]
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

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
Back
Top