You could use the Data Validation feature to prevent duplicates.- Select columns B and C
- Select from the menu Data\Data Validation
- On the DV Dialog:
- Allow: Custom
- Formula: =COUNTIFS($B:$B,$B1,$C:$C,$C1)<=1
- Define the message on the Error Alert tab
This will put the Last Scan in column L
Private Sub Worksheet_Change(ByVal Target As Range)
Const SCAN_CELL As String = "J2"
Const RANGE_BC As String = "D1:D10000"
Dim val, f As Range, rngCodes As Range
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Me.Range(SCAN_CELL)) Is Nothing Then
val = Trim(Target.Value)
If Len(val) = 0 Then Exit Sub
Set rngCodes = Me.Range(RANGE_BC)
Set f = rngCodes.Find(val, , xlValues, xlWhole)
If Not f Is Nothing Then
With f.Offset(0, 2)
.Value = .Value + 1
End With
Else
Set f = rngCodes.Cells(rngCodes.Cells.Count).End(xlUp).Offset(1, 0)
f.Value = val
f.Offset(0, 4).Value = "Not Found. Please Reference Maintenix System"
f.Offset(0, 2).Value = 1
End If
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
ElseIf Target.Column = 6 Then 'Column F
Range("L2").Value = Range("A" & Target.Row).Value
Range("L3").Value = Range("B" & Target.Row).Value
Range("L4").Value = Range("C" & Target.Row).Value
Range("L5").Value = Range("D" & Target.Row).Value
Range("L6").Value = Range("G" & Target.Row).Value
End If
End Sub
Bookmarks