sumsaam
Board Regular
- Joined
- Dec 31, 2012
- Messages
- 82
- Office Version
- 2010
- Platform
- Windows
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Const SCAN_CELL As String = "K2"
Const RANGE_BC As String = "B2:B5000"
Dim val, f As Range, rngCodes As Range, qty As Variant, QtyMode As Boolean
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
QtyMode = Me.Shapes("Check Box 1").OLEFormat.Object.Value = 1
If QtyMode Then qty = Application.InputBox(prompt:="Enter the Qty of " & val, Title:="Quantity box", Default:=1, Type:=1)
If Not qty Then
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 + IIf(QtyMode, qty, 1)
End With
Else
'This if block asks to add or not if non listed barcode scanned
If MsgBox("Item is out of List, add anyway?", vbYesNo + vbInformation, val) = vbYes Then
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 = IIf(QtyMode, qty, 1)
End If
'This if block asks to add or not if non listed barcode scanned
End If
End If
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
Target.Select
End Sub