Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Sub test()
  4.  
  5. Dim LastRow As Long
  6. Dim rngToSearch As Range, rngFound As Range
  7. Dim LookingValue As String
  8.  
  9. 'Create a with statement refer to the sheet that your data are store
  10. With ThisWorkbook.Worksheets("Sheet1")
  11. 'Assigg to LookingValue the barcode scanned
  12. LookingValue = "1234"
  13. 'Find the last row of column A
  14. LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
  15. 'Set the range to search for the barcode in
  16. Set rngToSearch = .Range("B2:B" & LastRow)
  17. 'Set to rngFound the results from the find
  18. Set rngFound = rngToSearch.Find(LookingValue, LookIn:=xlValues)
  19. 'If the result is nothing
  20. If rngFound Is Nothing Then
  21. 'Message box
  22. MsgBox "Barcode was not found."
  23. 'if you find a result
  24. Else
  25. 'Add 1 to the existing value
  26. .Cells(rngFound.Row, 4).Value = 1 + .Cells(rngFound.Row, 4).Value
  27. End If
  28.  
  29. End With
  30.  
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement