c.
gh
gu
c.
gh
gu
Private Sub txtID_Barcode_Change()
'the following line is just for debug to check that the barcode has been entered
MsgBox "New Data = " & TextBox1
Dim NewBarcode
Dim LastRow As Integer
Dim SearchRange As Range
NewBarcode = TextBox1.Value
'check to see if this barcode has been used
' do a ind on the previously loaded barcodes
'get last row in serch column
'LastRow = Range("E1").End(xlDown).Row
LastRow = Worksheets("Sheet1").Range("A1").SpecialCells(xlCellTypeLastCell).Row
Set SearchRange = Worksheets("Sheet1").Range(Cells(1, "B"), Cells(LastRow, "B"))
' find needs to go here - run out of time will have a look tommorrow and carry on
'if you have not solved it youself
End Sub
Here is some code that will check the Barcode being added against those already added. Currently it just raise a message box.
You will need to tweek this code to perform your current business function when this situation occurs
This requires that the Barcode be entered completely in one hit (Paste or scan) as the code runs on the entry of a single character if you type it in
Private Sub txtID_Barcode_Change()
'the following line is just for debug to check that the barcode has been entered
MsgBox "New Data = " & txtID_Barcode
Dim NewBarcode
Dim LastRow As Integer
Dim SearchRange As Range
Dim c
NewBarcode = txtID_Barcode.Value
'check to see if this barcode has been used
' do a ind on the previously loaded barcodes
'get last row in serch column
'LastRow = Range("E1").End(xlDown).Row
LastRow = Worksheets("Sheet1").Range("A1").SpecialCells(xlCellTypeLastCell).Row
Set SearchRange = Worksheets("Sheet1").Range(Cells(1, "B"), Cells(LastRow, "B"))
With SearchRange
Set c = .Find(What:=NewBarcode, LookIn:=xlValues, _
LookAt:=VBA.Trim(xlWhole), SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
End With
If Not c Is Nothing Then 'has been found
MsgBox NewBarcode & " Found"
End If
End Sub