There could be fancier ways, but since you have most of the code already, I just modified the last section a bit:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Item As String
Dim SearchRange As Range
Dim rFound As Range
Dim newDesc As String
Dim newQty As Long
'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 the here first:
Set SearchRange = Range("A1:A" & Range("A1").CurrentRegion.Rows.Count)
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:=xlPart, SearchOrder:=xlByRows _
, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
'Adds one to the Quantity:
rFound.Offset(0, 2).Value = rFound.Offset(0, 2).Value - 1
Else
'Writes the value for the Barcode-list:
newDesc = InputBox("Please enter the description for this new product")
newQty = InputBox("What is the quantity for this item? (After removing the current one)")
Range("A" & SearchRange.Rows.Count + 1).Value = Item
Range("A" & SearchRange.Rows.Count + 1).Offset(0, 1).Value = newDesc
Range("A" & SearchRange.Rows.Count + 1).Offset(0, 2).Value = newQty
End If
'Enable the Events again:
Application.EnableEvents = True
End Sub
Bookmarks