Probieren Sie den Code unten, es ist nicht so einfach wie ich es gerne hätte, aber es funktioniert.
Sobald Sie feststellen, dass der aktuelle Wert in Spalte "O" ein Duplikat hat, verwende ich die Find
Methode, um die nächste Übereinstimmung zu finden.
-Code
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 15 And Len(Target.Value) > 0 Then
If Evaluate("Countif(O:O," & Target.Address & ")") > 1 Then
Range("P1").Value = "DUPLICATE ENTRY EXISTS"
Dim RowDup As Long
Dim FindRng As Range
Dim LastRow As Long
LastRow = Cells(Rows.Count, Target.Column).End(xlUp).Row ' get last row with data in Column "O"
If Target.Row = 1 Then
Set FindRng = Range(Cells(Target.Row + 1, Target.Column), Cells(LastRow, Target.Column))
Else ' define a search range, substract target cell from active range in column "O"
Set FindRng = Application.Union(Range(Cells(1, Target.Column), Cells(Target.Row - 1, Target.Column)), Range(Cells(Target.Row + 1, Target.Column), Cells(LastRow, Target.Column)))
End If
' find thr row number in the column O (except Target cell)
RowDup = FindRng.Find(What:=Target.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
' get the hyperlink to the cell where the first dupliacte exists
Range("Q1").Formula = "=HYPERLINK(" & Range(Cells(RowDup, Target.Column), Cells(RowDup, Target.Column)).Address & ")"
End If
End If
Application.EnableEvents = True
End Sub
Kann es mehrere Duplikate für einen Eintrag geben? – CallumDA