Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub test()
- Dim LastRow As Long
- Dim rngToSearch As Range, rngFound As Range
- Dim LookingValue As String
- 'Create a with statement refer to the sheet that your data are store
- With ThisWorkbook.Worksheets("Sheet1")
- 'Assigg to LookingValue the barcode scanned
- LookingValue = "1234"
- 'Find the last row of column A
- LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
- 'Set the range to search for the barcode in
- Set rngToSearch = .Range("B2:B" & LastRow)
- 'Set to rngFound the results from the find
- Set rngFound = rngToSearch.Find(LookingValue, LookIn:=xlValues)
- 'If the result is nothing
- If rngFound Is Nothing Then
- 'Message box
- MsgBox "Barcode was not found."
- 'if you find a result
- Else
- 'Add 1 to the existing value
- .Cells(rngFound.Row, 4).Value = 1 + .Cells(rngFound.Row, 4).Value
- End If
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement