VBA & Macro Problems

How to Enter a Scan Date After Matching a Barcode in Excel VBA

John WilsonJohn Wilson Nov 11, 2026 870 views

Question details

The user needs to automatically record the current date and the scanned value into specific columns when a scanned barcode matches an existing entry in the worksheet.

Enter a Scan Date After Matching a Barcode in Excel VBA
Product
Excel
Device & OS
not provided
Scenario
Using a barcode scanner to track items in a spreadsheet, requiring automated data entry for the scan date and matched values to save time.
Observed behavior
Requires a VBA macro to find a matched barcode in column B, then output the scanned barcode to column N and the current date to column K.
Before you start

Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have designated a specific input column for your barcode scanner to enter data.

Solution 1Recommended

Use the Worksheet_Change VBA Event to Automate Barcode Logging

Implement a VBA macro that automatically triggers when a barcode is scanned, matches it against your database, and fills in the required date and values.

This solution utilizes the Worksheet_Change event, which runs automatically whenever a cell's value is modified. It listens for changes in your designated scan input column.

Once a scan is detected, the script searches for a match in your target column, and automatically updates the corresponding date and value columns in the same row.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor in Excel.

2
Access the Worksheet Module

In the Project Explorer pane on the left, double-click the specific worksheet (e.g., Sheet1) where you want the barcode scanning automation to occur.

3
Insert the VBA Code

Copy and paste your Worksheet_Change event code into the module window. Ensure the input column referenced in the code (like Me.Columns("M")) matches the column where your scanner inputs data.

4
Test the Barcode Scanner

Return to your worksheet, select a cell in your designated input column, and scan a barcode. The macro will instantly find the match in Column B and populate Columns K and N.

Use the Worksheet_Change VBA Event to Automate Barcode Logging
Macro Deployment: Always test VBA macros on a copy of your workbook first to ensure the column references align perfectly with your unique data structure.
Advanced Macro Support

Automate Barcode Tracking with WPS Spreadsheet

WPS Office provides robust support for VBA macros in its advanced editions, allowing you to seamlessly run automated barcode scanning scripts just like in Microsoft Excel.

  1. 1. Open the Workbook: Open your macro-enabled spreadsheet (.xlsm) in WPS Spreadsheet.
  2. 2. Access Developer Tools: Navigate to the Developer tab on the ribbon to access the VBA Editor.
  3. 3. Insert the Script: Paste the barcode tracking VBA script into the corresponding worksheet module.
  4. 4. Enable Macros: Enable macros in the security warnings and start scanning your barcodes to log dates automatically.
Full compatibility with Microsoft Excel (.xlsm) macro filesLightweight and fast spreadsheet processing for large datasetsFamiliar user interface for a seamless and easy transitionBuilt-in tools for advanced data validation and automation
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't the macro triggering when I scan a barcode?

If your barcode scanner is configured to press 'Enter' after scanning, the active cell changes immediately. Ensure your macro is monitoring the exact column where the scan is initially inputted before the 'Enter' keystroke moves the selection.

Can I change the columns used in this VBA code?

Yes. You can easily modify the column letters in the VBA code. For example, change 'Me.Columns("B")' to your specific tracking number column, and 'Me.Cells(matchRow, "K")' to your desired date column.

How do I format the date that appears in Column K?

The macro uses the standard VBA 'Date' function, which inputs the system's current date. You can format how this date looks directly in the spreadsheet by selecting Column K, right-clicking, choosing 'Format Cells', and picking your preferred date format.

Does this code cause errors if the scanned barcode is not found?

No. A properly written macro includes an 'If Not IsError(matchRow)' check. If the barcode is not found in the target column, the macro simply exits without doing anything, preventing VBA runtime errors.