Barcode Scanner Entry to Excel Database with Timestamp (3 Basic Cases)

The article will show you how to imply barcode scanner entry to excel database with timestamp. If you work in a shop, you need to keep a record of the time when a product is sold to a customer with its ID. Barcode provides us the ID of a product and also its property in some cases. To keep track of a product’s purchase and selling times, we need to enter the barcode scanner into Excel Database with a timestamp. So, it’s important to have the knowledge of how to put a barcode scanner with a timestamp.


Barcode Scanner Entry to Excel Database with Timestamp: 3 Basic Cases

In the dataset, we have some barcodes with corresponding timestamps.

barcode scanner entry to excel database with timestamp


1. Barcode Scanner Entry to Excel Database with Start and End Time

In this section, I will show you how to apply barcode scanner entries to Excel databases with a timestamp of both start and end times. Let’s go through the process below.

Steps:

  • First, go to Developer >> Visual Basic.

  • After that, the VBA editor window will appear. Select Insert >> Module.

barcode scanner entry to excel database with timestamp

  • Thereafter, type the following code in the VBA
Sub BarcodeTimestamp()
Dim Bar_Code As String
Dim Barcode_Range As Range
Dim Row_Number As Long
Bar_Code = ActiveSheet.Cells(4, 3)
If Bar_Code <> "" Then
Set Barcode_Range = ActiveSheet.Range("B5:B100").Find(What:=Bar_Code, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Barcode_Range Is Nothing Then
ActiveSheet.Range("B5:B100").Find("").Select
ActiveCell.Value = Bar_Code
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Date & "  " & Time
ActiveCell.NumberFormat = "dd/mm/yyyy h:mm:ss AM/PM"
ActiveSheet.Cells(4, 3) = ""
Else
Row_Number = Barcode_Range.Row
ActiveSheet.Range(Cells(Row_Number, 2), Cells(Row_Number, 10)).Find("").Select
ActiveCell.Value = Date & "  " & Time
ActiveCell.NumberFormat = "dd/mm/yyyy h:mm:ss AM/PM"
ActiveSheet.Cells(4, 3) = ""
End If
End If
ActiveSheet.Cells(4, 3).Select
End Sub

We declared some necessary variables in the code, like Bar_Code As String, Barcode_Range As Range and Row_Number As Long. We also set the position of the Bar_code in C4 (ActiveSheet.Cells(4,3)) and used ActiveSheet.Range, ActiveCell.Value etc. properties of VBA and ran it. In addition, we set the Time Format to “dd/mm/yyyy h:mm:ss” so that we can properly differentiate the timestamps. You can use the pattern of my dataset because in that case, you don’t need to modify the code. Here is a preview of my dataset structure.

barcode scanner entry to excel database with timestamp

  • Next, open the Worksheet on which you will enter the barcode scanner id from the VBA Project and type the following code in it.
Private Sub Worksheet_Change(ByVal target_value As Range)
If Not Intersect(target_value, Me.Range("C4")) Is Nothing Then
Call BarcodeTimestamp
Application.EnableEvents = True
End If
End Sub

barcode scanner entry to excel database with timestamp

We just called the BarcodeTimestamp Macro and enabled the Application Events by this Private Sub Procedure.

  • After that, go back to your sheet and run the Macro.

barcode scanner entry to excel database with timestamp

  • Next, type the barcode number in the corresponding cell.

  • After that, press the ENTER button and you will see the Product ID with its timestamp of Start Time. This time refers to the time when your product is brought to the store.

barcode scanner entry to excel database with timestamp

  • Suppose you sold this product. Just copy the Barcode number in the cell where you input the barcodes and you will see the End Time in the corresponding cell.

  • If you want to update the timestamp, you can either delete the previous timestamp and apply for a new entry or you can simply copy the barcode I set some new cells to keep the updated timestamps.

barcode scanner entry to excel database with timestamp

  • Later, in the following picture, I just filled the blank cells with random barcodes and their corresponding previous and updated timestamps.

Thus you can apply barcode scanner entries to excel databases with timestamps.


2. Barcode Scanner Entry with Timestamp of Start Time Only

If you don’t require putting the end time as timestamps, you can use a much simpler procedure. Let’s go through it in the following description.

Steps:

  • Follow the procedure of Section 1 to open the VBA Editor.
  • Next, open the Worksheet on which you will enter the barcode scanner id from the VBA Project and type the following code in it.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim x As Integer
For x = 5 To 200
If Cells(x, 2).Value <> "" And Cells(x, 3).Value = "" Then
Cells(x, 3).Value = Date & " " & Time
Cells(x, 3).NumberFormat = "dd/mm/yyyy h:mm:ss AM/PM"
End If
Next
End Sub

barcode scanner entry to excel database with timestamp

Here, we declared x As Integer, used a VBA If Statement and some properties like Cells.Value and Cells.NumberFormat to create the timestamp.

  • After that, go back to your sheet and type a barcode.

  • Later, press the ENTER button and you will see the timestamp beside it.

barcode scanner entry to excel database with timestamp

  • In the following picture, I just filled the blank cells with random barcodes and their corresponding timestamps.

Thus you can get barcode scanner entries to excel databases with timestamps.

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


3. Applying Excel Formula to Enter Barcode to Database with Timestamp

If you are not a VBA guy, you can apply IF and NOW functions to enter a barcode scanner to an Excel database with timestamp. It’s not going to be as effective as the previous methods though. Let’s go through the procedure below.

Steps:

  • First, set your Calculation Option to Manual as the NOW function is a dynamic function which will always provide the current time after any command is executed.

barcode scanner entry to excel database with timestamp

  • Thereafter, type any barcode in cell B5 and type the following formula in cell C5.

=IF(B5<>"",NOW(),"")

Here, the IF function operates a logical test of whether B5 is empty or not. If it’s not empty then the formula returns the current time with the help of the NOW function. Otherwise, it returns blank.

  • Hit the ENTER button and you will see the corresponding timestamp.

barcode scanner entry to excel database with timestamp

  • For the second timestamp and barcode, you need to type the barcode first, then type the following formula and press ENTER.

=IF(B6<>"",NOW(),"")

  • After that, I filled the blank cells with random barcodes and timestamps in a similar manner.

barcode scanner entry to excel database with timestamp

Thus you can enter a barcode scanner to an Excel database with timestamps using Excel formula. The problem with this method is that you have to keep entering the formula manually.

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


Practice Section

Here, I’m giving you the dataset of this article so that you can practice these methods on your own.


Download Practice Workbook


Conclusion

In a nutshell, you will learn some easy and effective methods of how to imply barcode scanner entries to the Excel Database with timestamps. If you have any better methods or questions or feedback regarding this article, please share them in the comment box. This will help me enrich my upcoming articles.


Related Articles


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

Get FREE Advanced Excel Exercises with Solutions!
Meraz Al Nahian
Meraz Al Nahian

Md. Meraz Al Nahian has worked with the ExcelDemy project for over 1.5 years. He wrote 140+ articles for ExcelDemy. He also solved a lot of user problems and worked on dashboards. He is interested in data analysis, advanced Excel, statistics, and dashboards. He also likes to explore various Excel and VBA applications. He completed his graduation in Electrical & Electronic Engineering from Bangladesh University of Engineering & Technology (BUET). He enjoys exploring Excel-related features to gain efficiency... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo