VBA prevent wrong item being scan

handri

Board Regular
Joined
Nov 25, 2017
Messages
88
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi,

I have a cell start from C7 to C10001.
The data here is between PASSED and WRONG.
which i created a simple barcode scanner purpose.
How i can use a VBA code to stop scanning purpose if WRONG item scanned in the cell(C7 to C10001)
Also a popping error message tell that you scan a wrong item.
And for passes nothing change an you can go for the next scan.
Only for the WRONG result appear in related cell.

thank you
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Is the scan input in another column? in which column?
In column C do you have formulas?
You could describe an example of what you have.
 
Upvote 0
yes, the input is in A7. C7 to C10001 is output.
At the output the formula as below

=IF(A7="","",IF(ISNUMBER(SEARCH(B$4,A7)), "PASSED", "WRONG"))

I need to stop action if WRONG item are input also with a popping message to alert.

thank you
 
Last edited:
Upvote 0
Put the following code in sheet event

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Count > 1 Then Exit Sub
  If Target.Value = "" Then Exit Sub
  If Not Intersect(Target, Range("A:A")) Is Nothing Then
    If Cells(Target.Row, "C").Value = "WRONG" Then
      MsgBox "Scan a wrong item", vbCritical
      Target.Select
    End If
  End If
End Sub

SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.
 
Upvote 0
Thank you Sir,

Its work for me..

thank you

Put the following code in sheet event

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Count > 1 Then Exit Sub
  If Target.Value = "" Then Exit Sub
  If Not Intersect(Target, Range("A:A")) Is Nothing Then
    If Cells(Target.Row, "C").Value = "WRONG" Then
      MsgBox "Scan a wrong item", vbCritical
      Target.Select
    End If
  End If
End Sub

SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,573
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top