I am trying to get Excel to work as a inventory scan reader. I\'m having trouble with scanning because it constantly adds to col A when I scan and even if its a duplicate, I wan
Place this code in the sheet code module (right-click on the tab and select "view code").
Your list headers go in A4 (barcode) B4 (description) C4 (count). Select cell A1 and start scanning. If it finds a match in the list it will update the count, if not then it adds a new line. I tested just by typing in values, but should wortk the same way with a scanner as long as it's sending {enter} with each scan.
Private Sub Worksheet_Change(ByVal Target As Range)
Const SCAN_CELL As String = "A1"
Const RANGE_BC As String = "A5:A500"
Dim val, f As Range, rngCodes As Range
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(SCAN_CELL)) Is Nothing Then Exit Sub
val = Trim(Target.Value)
If Len(val) = 0 Then Exit Sub
Set rngCodes = Me.Range(RANGE_BC)
Set f = rngCodes.Find(val, , xlValues, xlWhole)
If Not f Is Nothing Then
With f.Offset(0, 2)
.Value = .Value + 1
End With
Else
Set f = rngCodes.Cells(rngCodes.Cells.Count).End(xlUp).Offset(1, 0)
f.Value = val
f.Offset(0, 1).Value = "enter description"
f.Offset(0, 2).Value = 1
End If
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
Target.Select
End Sub