Barcode Scanner Macro

cjaneczko

New Member
Joined
Feb 11, 2014
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I'd like to setup some sort of a macro in excel with a barcode scanner I have. We have a factory with a large number of machines which are all bar coded that also have travelers with the production order in a barcode format. Right now someone walks the line and manually writes which work order is on which machine. Id like to use a scanner to expedite the process. The macro Id like to create is in when the cursor is in cell A2, the barcode is scanned and the work order number is displayed. After its scanned, move to cell B2, scan the machine and the machine number is displayed. After the machine is input id like the cursor to index to the next available row and first column (ex cell A3). Then the process is repeated. This would then end in a list of Work orders in column A and the corresponding machines in column B.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I am using this now and its putting the barcodes in correctly for Columns A and B, but it wont go down to the next row (A3) and create a new prompt for the next workorder. The macro just ends.

Sub Barcode()Dim traveler As String, lr As Long
Dim machine As String
Dim i As Integer


traveler = InputBox("Enter Work Order Number", "Data Entry Form")
machine = InputBox("Enter Machine Number", "Data Entry Form")


For i = 1 To LastRow
If traveler = "" Then
Exit Sub
Else
lr = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & lr).Value = traveler
lr = Range("B" & Rows.Count).End(xlUp).Row + 1
Range("B" & lr).Value = machine
End If
Next i


End Sub
 
Upvote 0
You are saying for i = 1 to Lastrow - so it should loop until the last row - but not telling it what last row is...

It looks like you want to loop until you cancel out? If so something like:

Code:
Sub Barcode()
Dim t As String: t = "."
Dim lr As Long
Dim m As String


lr = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row + 1


Do While Len(t) > 0


    t = InputBox("Enter Work Order Number", "Data Entry Form")
    If t = vbNullString Then Exit Sub
    
    m = InputBox("Enter Machine Number", "Data Entry Form")
    If m = vbNullString Then Exit Sub
    
    With ActiveSheet
        .Range("A" & lr).Value = t
        .Range("B" & lr).Value = m
    End With
    
    lr = lr + 1


Loop


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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