I’m trying to use a barcode pistol to check some serial numbers. The problem is that the tag has multiple codes and sometimes the pistol upload the wrong information into Excel.
All the serial numbers start with an “S”. So my idea is when Excel register the serial number it verifies if it starts with as “S”. If it starts with “S”, no sound is played, and it goes to the next cell, else plays a sound that indicates that the code is not correct.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Range
Application.EnableEvents = False
On Error GoTo ExitSub
If Not Intersect(Target, Me.Columns("H")) Is Nothing Then
For Each Cell In Target
If Left(Cell.Value, 1) <> "S" Then
Call PlayCustomSound
End If
Next Cell
End If
ExitSub:
Application.EnableEvents = True
End Sub
I almost have it working, but the problem I have is that it verifies the next cell and not the code that was placed on the previous cell.
If with my mouse I just click on one that has an “S”, no sound is played, if it doesn’t have an “S” it’s playing the sound.
If possible, I would like to add that when it doesn’t have an “S”, instead of going to the next cell it keeps on the same cell until I upload a code starting with an “S”.
user26686853 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.