Machine-readable code is numbers and a pattern of parallel lines displaying manufacturer and product info upon scanning. Excel worksheets can be used as barcode scanners using a macro. Excel barcode scanner macro can display product details in its sheets upon entering scanned barcode numbers.
Barcode and Its Convention
Mainly a 12-digit number format with patterns known as the Universal Product Code, which is used as barcodes around the world. There are other versions of barcodes available. However, in this article, we demonstrate the UPC-A version of the Universal Product Code as barcodes. The UPC-A version has a depiction like the below image.
The first 6 digits of the UPC-A barcode define the Company, the latter 5 digits the product, and the last digit is the Check Digit.
How to Create a Barcode Scanner Macro in Excel: Step-by-Step Procedures
Go through the below steps to create an Excel barcode scanner. We will compile the scanned barcode numbers into a worksheet and then will create an inventory record sheet. Finally, we will use a Macro to accomplish the task.
Step 1: Compiling the Barcode into Excel Worksheet
Firstly, you need to compile the scanned barcode numbers into a worksheet as depicted in the image below. Make sure you have all the necessary information regarding the products and manufacturer, as you will be needing them in the macro.
Read More: How to Create Barcode Without Font in ExcelÂ
Step 2: Creating an Inventory Record Worksheet with Desired Product Info
Now you want the product information stored in barcodes whenever you run a macro.
- Name the column with desired product info of what you want to fetch.
- You need to assign these columns in the macro to display product info in them.
Read More: Barcode Scanner Entry to Excel Database with TimestampÂ
Step 3: Inserting a Macro Button into the Barcode Worksheet
It’s annoying to run a macro using the Microsoft Visual Basic window. Therefore, use a Macro Button to run the macro any time after the new barcode insertion.
Read More: How to Use Barcode Scanner in ExcelÂ
Step 4: Assigning a Macro to Fetch Info into the Inventory Record
The inserted macro button needs a macro to be assigned. The macro needs to be written in a way that satisfies all the desired requirements.
- Right-click on the Macro Button then select View Macro.
- Paste or modify the following macro to display desired product info of the inserted barcodes.
Private Sub CommandButton1_Click()
Dim mBarcode As String
Dim mCode, mMan As String
Dim mRng As Range
Dim mDes, ManDes As String
Dim mRowNumber, mCount As Long
Dim mRow As Long
Dim mLastRow As Long
R = 6
mLastRow = Sheet2.Cells(Rows.count, 2).End(xlUp).Row
For R = 6 To mLastRow
mBarcode = Sheet2.Cells(R, 2)
Sheet1.Activate
mRow = ActiveSheet.Cells(Rows.count, 2).End(xlUp).Row + 1
If mBarcode <> "" Then
Set mRng = ActiveSheet.Columns("B:B").Find(what:=mBarcode, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If mRng Is Nothing Then
Sheet1.Cells(mRow, 2) = mBarcode
Sheet1.Cells(mRow, 3) = Mid(mBarcode, 7, 5)
mCode = Sheet1.Cells(mRow, 3)
If Left(mCode, 4) = "6345" Then
mDes = "Black Point Pen"
End If
If Left(mCode, 4) = "5341" Then
mDes = "Blue Point Pen"
End If
If Left(mCode, 4) = "2365" Then
mDes = "Red Point Pen"
End If
Sheet1.Cells(mRow, 4).Value = mDes
Sheet1.Cells(mRow, 5) = Mid(mBarcode, 2, 5)
mMan = Sheet1.Cells(mRow, 5)
If Mid(mMan, 1, 5) = "23456" Then
ManDes = "Sheely Pen Corp."
End If
Sheet1.Cells(mRow, 6) = ManDes
Sheet2.Cells(R, 2).ClearContents
GoTo ende
Else
MsgBox "Barcode Already Existing"
End If
End If
ende:
Next R
End Sub
Macro Explanation
- Firstly, the macro defines the variables.
Dim mBarcode As String
Dim mCode, mMan As String
Dim mRng As Range
Dim mDes, ManDes As String
Dim mRowNumber, mCount As Long
Dim mRow As Long
Dim mLastRow As Long
- The barcodes start from row RÂ of Sheet2. Excel VBA Cells Property assigns it.
mBarcode = Sheet2.Cells(R, 2)
- Sheet1 gets activated and Excel finds barcodes using VBA Cell Property.
Sheet1.Activate
mRow = ActiveSheet.Cells(Rows.count, 2).End(xlUp).Row + 1
If mBarcode <> "" Then
Set mRng = ActiveSheet.Columns("B:B").Find(what:=mBarcode, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
- VBA IF imposes conditions to display text depending on the specific digits of barcodes.
If Left(mCode, 4) = "6345" Then
mDes = "Black Point Pen"
End If
or
If Mid(mMan, 1, 5) = "23456" Then
ManDes = "Sheely Pen Corp."
End If
â§Note: This type portion of the macro is highly sensitive. You need to modify or change similar macro lines to fit your demands. Otherwise, this macro will be useless in your case.
- After displaying the info, Excel clears the inserted barcodes.
Sheet2.Cells(R, 2).ClearContents
Read More: [Solved] Barcode Scanner Not Going to Next Line in Excel
Step 5: Running VBA Macro to Work the Excel Barcode Scanner
After assigning the macro to the Macro Button, you need to activate the macro by pressing F5.
- Go to the Scanned Barcode Data sheet, and enter barcodes.
- Click on the Fetch Product Info macro button.
- Instantly, Excel displays the product info as shown in the picture below.
Read More: Creating Barcode Scanner to Track Check in & Check out Time in Excel
Download Excel Workbook
Use the attached Excel file as a free Template. Make sure you modify the attached macro according to your needs. The dataset works as an Excel barcode scanner auto-enter.
Conclusion
This article discusses the UPC-A type barcode and its Excel barcode scanner macro. Users may have different versions of barcodes. In those cases, they need to modify the macro according to the barcode convention. Comment if you need further clarification or have anything to add.
There are hundreds of articles regarding Excel and its issues.
Related Articles
- How to Create Barcode in Excel
- How to Generate Barcode Numbers in ExcelÂ
- How to Convert Numbers to Barcode in ExcelÂ
- How to Generate 2D Barcode in ExcelÂ
- How to Use EAN 13 Barcode Generator in ExcelÂ
- How to Create Barcode Using 3 of 9 Font in Excel
- How to Calculate Barcode Check Digit with Excel Formula
- How to Add Barcode Font in ExcelÂ
- How to Use Code 39 Barcode Font for Excel
- How to Generate Code 128 Barcode Font for Excel
- How to Move Barcode Scanner to Next Row in ExcelÂ
- How to Make Auto Enter with Barcode Scanner in Excel
- How to Print Barcode Labels in ExcelÂ