Try this...
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
Dim rngRow As Range
If Target.Cells.Count = 1 Then
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 If
'Data Validation for columns B:C
If Not Intersect(Columns("B:C"), Target) Is Nothing Then
For Each rngRow In Target.EntireRow.Columns("B:C").Rows
If rngRow.Cells(1, 1) <> "" And rngRow.Cells(1, 2) <> "" Then
If Evaluate("=SUMPRODUCT(--(" & Me.UsedRange.Columns("B").Address & "&" & Me.UsedRange.Columns("C").Address & "=" & rngRow.Cells(1, 1).Address & "&" & rngRow.Cells(1, 2).Address & "))>1") Then
MsgBox "PN: " & rngRow.Cells(1, 1) & vbLf & _
"SN: " & rngRow.Cells(1, 2), vbExclamation, "Duplicate Entry"
Application.EnableEvents = False
Intersect(rngRow, Target).ClearContents
Application.EnableEvents = True
End If
End If
Next
End If
End Sub
Bookmarks