How to Create a Barcode Scanner to Track Check-in & Check-out Times in Excel (Step-by-Step)

 

Step 1: Insert a Command Button in Excel

  • Define a cell where you will put the input barcode. Here, I will put it in cell C4.
  • Create a table where you want the output. Here, I created a table that contains the Barcode, Check-in, and Check-out times.

Insert Command Button in Excel for Barcode Scanner to Track Chcek in and Check Out

  • Go to the Developer tab.
  • Select Insert.
  • Select the Command Button from ActiveX Controls.

  • Click and drag your mouse cursor where you want the Command Button.

Dragging Mouse Cursor to Create Barcode Scanner for Check in and Check Out in Excel

  • You will see that you have inserted a Command Button.

  • To change the properties of the Command Button, Right-Click on it.
  • Select Properties.

Changing Properties of Command Button to Create Barcode Scanner to Track Check in and Check out in Excel

  • The Properties dialog box will appear.
  • Change the caption as you want. Here, I changed mine to Scan.

  • To change the font, select Font.
  • Click on the marked button in the following picture.

  • The Font dialog box will appear.
  • You can change the Font, Font Style, and Size as you like. I selected Bold as the Font Style and 14 as the Size.
  • Select OK.

  • In the following picture, you can see how my Command Button looks at this point.

Read More: How to Use Barcode Scanner in Excel


Step 2: Write VBA Code

  • Right-click on the Command Button.
  • Select View Code.

Write VBA Code for Barcode Scanner to Track Check in and Check out

  • A module will open with a Private Sub Procedure.
  • Enter the following code in that module:
Private Sub CommandButton1_Click()
Dim bar_code As String
Dim barcode_range As Range
Dim row_no As Long
bar_code = ActiveSheet.Cells(4, 3)
    Set barcode_range = ActiveSheet.Range("B8:D100").Columns(1).Find(What:=bar_code, _
    LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If barcode_range Is Nothing Then
        ActiveSheet.Range("B8:D100").Columns(1).Find("").Select
        ActiveCell.Value = bar_code
        ActiveCell.Offset(0, 1).Select
        ActiveCell.Value = Date & "  " & Time
        ActiveCell.NumberFormat = "m/d/yyyy h:mm AM/PM"
        ActiveSheet.Cells(4, 3) = ""
    Else
        row_no = barcode_range.Row
        ActiveSheet.Cells(row_no, 2).Select
        ActiveCell.Offset(0, 2).Select
        ActiveCell.Value = Date & "  " & Time
        ActiveCell.NumberFormat = "m/d/yyyy h:mm AM/PM"
        ActiveSheet.Cells(4, 3) = ""
    End If
End Sub

How Does the Code Work?

  • Here, a Private Sub Procedure was already created by the Command Button named CommandButton1_Click.
  • Then, I declared a variable named bar_code as String, a variable named barcode_range as Range, and another variable named row_no as Long.
  • Next, I defined the bar_code by using the ActiveSheet.Cells property. Here, Cells(4, 3) mean cell C4.
  • After that, I used the Set Statement to define the barcode_range. Then, I used the Find method to find the bar_code in the barcode_range.
  • Further, I used the If Statement to give 2 different situations. If the bar_code does not match any value in the barcode_range, then it will return the barcode and the check-in time in the cell beside the barcode. Otherwise, it will return the checkout time.
  • Then, I ended the If Statement.
  • Finally, I ended the Sub Procedure.
  • Lastly, Save the code and go back to your worksheet.

Read More: Barcode Scanner Entry to Excel Database with Timestamp


Step 3: Run Macros

  • Type the barcode in the input cell.

Run Macros for Barcode Scanner to Track Check in and Check out in Excel

  • Click on the Command Button.

  • You will see that the barcode and the time you scanned it are entered in the output table as Check-in.

  • When the product is going out of the warehouse, enter the barcode in the input cell again.
  • Select Scan.

  • You will see that the Checkout time is entered in the output table.

Read More: How to Use Barcode Scanner for Inventory in Excel


Final Output

In the following dataset, I tracked check-in and check-out times for 5 products using the Excel barcode scanner. It gives accurate results with a single click.

Final Output for Barcode Scanner to Track Check in and Check out in Excel

Read More: How to Move Barcode Scanner to Next Row in Excel


Things to Remember

  • It should be noted that if you are working with VBA, you must save the Excel file as an Excel Macro-Enabled Workbook. Otherwise, the VBA code won’t work.

Practice Section

A practice sheet for creating a barcode scanner to track check-in and check-out time in Excel is here.

Practice Sheet for Barcode Scanner to Track Check in and Check out in Excel


Download the Practice Workbook

You can download the practice workbook from here.


Related Articles


<< Go Back to Use Barcode ScannerBarcode in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mashhura Jahan
Mashhura Jahan

Mashhura Jahan, BSc in Industrial and Production Engineering from Bangladesh University of Engineering and Technology, invested 1.5 years at ExcelDemy. In roles like Excel & VBA Content Developer, Excel Charts, and Dashboard course trainer, she wrote 90+ articles. She was previously part of the forum support team and a junior software analyst on the Excel Add-in project. With interests spanning Excel, VBA, Power Query, Python, Data Science, and Software Development, Mashhura brings a diverse skill set to her... Read Full Bio

4 Comments
  1. Works great but I want to use it to track equipment that is under calibration control. I can’t get it recognize a duplicate entry and create another entry/timestamp after it was checked in/out. it just keeps updating the last cell. can you help?

    • Reply Lutfor Rahman Shimanto
      Lutfor Rahman Shimanto Jan 15, 2024 at 10:48 AM

      Hello NC

      Thanks for sharing your requirements. You wanted a setup not to overwrite the existing entry but to create a new entry timestamp when an item is checked in or out more than once.

      I am delighted to inform you that I have developed an Excel VBA Sub-procedure to fulfil your requirements. So, follow these steps:

      1. Press Alt+F11 to the VBA Editor window.

      2. Click on Insert followed by Module.

      3. Insert the following code in the module and Run.

      
      Sub DuplicateCheckInAndOut()
          
          Dim ws As Worksheet
          Dim lastRow As Long
          Dim searchValue As Variant
          Dim cellB As Range
          Dim foundCell As Range
          Dim loopingRange As Range
          Dim foundInMiddle As Boolean
          
          Set ws = ThisWorkbook.Sheets("Sheet1")
          
          lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
          
          searchValue = ws.Range("C4").Value
          
          If lastRow < 9 Then lastRow = 9
          
          Set loopingRange = ws.Range("B9:B" & lastRow)
          Set foundCell = loopingRange.Find(What:=searchValue, LookIn:=xlValues, LookAt:=xlWhole)
          
          If foundCell Is Nothing Then
              If lastRow = 9 Then
                  ws.Cells(lastRow, "B").Value = searchValue
                  ws.Cells(lastRow, "C").Value = Date & "  " & Time
                  ws.Cells(lastRow, "C").NumberFormat = "m/d/yyyy h:mm AM/PM"
              Else
                  ws.Cells(lastRow + 1, "B").Value = searchValue
                  ws.Cells(lastRow + 1, "C").Value = Date & "  " & Time
                  ws.Cells(lastRow + 1, "C").NumberFormat = "m/d/yyyy h:mm AM/PM"
              End If
              
              Exit Sub
              
          End If
          
          For Each cellB In loopingRange
              
              If cellB.Value = searchValue Then
                  If IsEmpty(cellB.Offset(0, 2).Value) Then
                      cellB.Offset(0, 2).Value = Date & "  " & Time
                      cellB.Offset(0, 2).NumberFormat = "m/d/yyyy h:mm AM/PM"
                      foundInMiddle = False
                  Else
                      If cellB.Row = lastRow Then
                          ws.Cells(lastRow + 1, "B").Value = searchValue
                          ws.Cells(lastRow + 1, "C").Value = Date & "  " & Time
                          ws.Cells(lastRow + 1, "C").NumberFormat = "m/d/yyyy h:mm AM/PM"
                      Else
                          foundInMiddle = True
                      End If
                  End If
              End If
          
          Next cellB
          
          If foundInMiddle = True Then
              ws.Cells(lastRow + 1, "B").Value = searchValue
              ws.Cells(lastRow + 1, "C").Value = Date & "  " & Time
              ws.Cells(lastRow + 1, "C").NumberFormat = "m/d/yyyy h:mm AM/PM"
          End If
          
      End Sub
      

      After inserting the bar code and running the sub-procedure, you will see an output like the following GIF.

      Hopefully, the idea will help you to reach your goal. I have attached the solution workbook. Good luck.

      DOWNLOAD SOLUTION WORKBOOK

      Regards
      Lutfor Rahman Shimanto
      Excel & VBA Developer
      ExcelDemy

    • Hello Larry,

      To add the date to column K of the matched row of TCN of column B, you will need to use the Date function. It will provide the current date.

      Here, I updated the VBA code to add the date. Make sure to place this code in the appropriate worksheet module where you are scanning the barcodes.

      Private Sub Worksheet_Change(ByVal target As Range)
          If Not Intersect(target, Columns("M")) Is Nothing Then
              Z = Intersect(target, Columns("M")).Value
              If IsNumeric(Z) Then
                  x = Application.Evaluate("MATCH(" & Z & ",B:B,0)")
              Else
                  x = Application.Evaluate("MATCH(" & Chr(34) & Z & Chr(34) & ",B:B,0)")
              End If
              If Not IsError(x) Then
                  Application.Goto Cells(x, 15)
                  Cells(x, 11).Value = Date & " " & Time ' Adds the current date to column K
              End If
          End If
      End Sub
      

      Regards
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo