Hello, I am trying to set up an automatic case counter with a barcode scanner. I found a tutorial online with a basic one but I can't get it to work I keep getting "Compile error: sub or function not defined"
Here's the code currently:
Sheet1 Received:
Sub receive()
Dim barcode As String
Dim rng As Range
Dim rownumber, count As Long
Dim rec As Long
barcode = Sheet3.Cells(2, 2)
count = Sheet3.Cells(2, 1).Value
Sheet1.Activate
If barcode <> "" Then
Set rng = ActiveSheet.Columns("a:a").Find(what:=barcode, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If rng Is Nothing Then
MsgBox "number not found"
GoTo ende
Else
If count > 1 Then
rng.Offset(0, 3).Value = rng.Offset(0, 3).Value + count
Else
rng.Offset(0, 3).Value = rng.Offset(0, 3).Value + 1
End If
Sheet3.Cells(2, 2) = ""
End If
Sheet3.Cells(2, 1) = ""
End If
ende:
Sheet3.Activate
Sheet3.Cells(2, 2).Select
End Sub
Sheet3 scan-in:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("B2")) Is Nothing Then
Call receive
Application.EnableEvents = True
End If
End Sub
If anyone could help me understand what I'm doing wrong, I would appreciate it.
Here's the code currently:
Sheet1 Received:
Sub receive()
Dim barcode As String
Dim rng As Range
Dim rownumber, count As Long
Dim rec As Long
barcode = Sheet3.Cells(2, 2)
count = Sheet3.Cells(2, 1).Value
Sheet1.Activate
If barcode <> "" Then
Set rng = ActiveSheet.Columns("a:a").Find(what:=barcode, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If rng Is Nothing Then
MsgBox "number not found"
GoTo ende
Else
If count > 1 Then
rng.Offset(0, 3).Value = rng.Offset(0, 3).Value + count
Else
rng.Offset(0, 3).Value = rng.Offset(0, 3).Value + 1
End If
Sheet3.Cells(2, 2) = ""
End If
Sheet3.Cells(2, 1) = ""
End If
ende:
Sheet3.Activate
Sheet3.Cells(2, 2).Select
End Sub
Sheet3 scan-in:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("B2")) Is Nothing Then
Call receive
Application.EnableEvents = True
End If
End Sub
If anyone could help me understand what I'm doing wrong, I would appreciate it.