Hi Watersboy,
This does the trick:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Item As String
Dim strDscrpt As String
Dim strPrice As String
Dim SearchRange As Range
Dim rFound As Range
'Don't run the macro if:
'Target is not a single cell:
If Target.Cells.Count > 1 Then Exit Sub
'or Target belongs to the A1.CurrentRegion:
If Not Intersect(Target, Range("A1").CurrentRegion) Is Nothing Then Exit Sub
'Avoid the endless loop:
Application.EnableEvents = False
'Looks for matches from here first:
Set SearchRange = Range("A1:A" & Range("A1").CurrentRegion.Rows.Count)
If Len(Target) = 16 Then
If Right(Target, 5) = "-0000" Then
Target = Left(Target, 11)
ElseIf Right(Target, 1) = "0" Then
Target = Left(Target, 15): End If
End If
Item = Target.Value
'Clears the Target:
Target.Value = ""
If Application.WorksheetFunction.CountIf(SearchRange, Item) > 0 Then
'There's a match already:
Set rFound = Columns(1).Find(What:=Item, After:=Cells(1, 1) _
, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows _
, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
'Adds one to the Quantity:
rFound.Offset(0, 2).Value = rFound.Offset(0, 2).Value + 1
rFound.Activate
Application.Goto ActiveCell, True
Else
'Writes the value for the Barcode-list:
Range("A" & SearchRange.Rows.Count + 1).Value = Item
'Looks for the match from sheet "Inventory" column A
With Sheets("Inventory")
Set rFound = .Columns(1).Find(What:=Item, After:=.Cells(1, 1) _
, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows _
, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
On Error GoTo 0
If Not rFound Is Nothing Then
'Writes the Product Name and adds 1 to the Quantity column:
Range("B" & SearchRange.Rows.Count + 1).Value = rFound.Offset(0, 1).Value
Range("C" & SearchRange.Rows.Count + 1).Value = 1
'Scroll worksheet to the current item in case user want to see it or work with it.
Range("C" & SearchRange.Rows.Count + 1).Activate
Application.Goto ActiveCell, True
Else
'The Product isn't in the Inventory sheet.
'sound beep to alert user to add description and price.
Range("C" & SearchRange.Rows.Count + 1).Value = 1
Beep
For i = 1 To 15000000
'just killing one second or so, so we can get a second 'beep' in.
Next i
Beep
' IF user is quick to scan another barcode then the description would be entered as that barcode.
' So we avoid this by checking if the discription entered is a number or if its blank and loop
' until we get the user to enter some text. If a description is actually a number then user should procede the number
' with a single quote mark. This ensures that the user really want to enter a number as a description.
Do
strDscrpt = InputBox("Enter Description for Barcode: " & Range("A" & SearchRange.Rows.Count + 1).Value & vbCr & vbLf & "(24 characters max)", "Item Not found in Inventory List")
Loop While IsNumeric(strDscrpt) Or (Len(Trim(strDscrpt)) = 0)
Range("B" & SearchRange.Rows.Count + 1).Value = strDscrpt
Beep
Do
strPrice = InputBox("Now enter the regular PRICE for: " & UCase(strDscrpt) & vbCr & vbLf & "(With decimal point. example: 12.99)", "Price for Barcode: " & Range("A" & SearchRange.Rows.Count + 1).Value)
Loop While Not IsNumeric(strPrice)
Range("D" & SearchRange.Rows.Count + 1).Value = Val(strPrice)
'Scroll worksheet to the current item in case user want to see it or work with it.
Range("C" & SearchRange.Rows.Count + 1).Activate
Application.Goto ActiveCell, True
End If
End With
End If
Range("F1").Value = "Scan Barcode Here"
Range("F1").Select
'Enable the Events again:
Application.EnableEvents = True
End Sub
Bookmarks