another approach here
Sub dp2()
Dim n&, c As Range, rng As Range, Dic As Object
Set Dic = CreateObject("Scripting.Dictionary")
Dic.comparemode = vbTextCompare
Set rng = Range("A8:A" & Cells(Rows.Count, "A").End(xlUp).Row)
n = 8
For Each c In rng
If Dic.exists(c.Value2) And Dic(c.Value2) = 0 Then
Dic(c.Value2) = 1
Cells(n, "D").Value2 = c.Value2
n = n + 1
ElseIf Not Dic.exists(c.Value2) Then
Dic.Add c.Value2, 0
End If
Next c
End Sub
, :
1) : Columns(4).RemoveDuplicates Columns:=Array(1)
:
Range("D8:D" & Cells(Rows.Count, "D").End(xlUp).Row).RemoveDuplicates Columns:=1
2) :
lastrow = Range("D:D").End(xlDown).Row
# 8 , , : lastrow = Cells(Rows.Count, "D").End(xlUp).Row
3), to 1 step -1 to 8 step -1
, , :
Sub dp()
Dim AR As Long, p1 As Range, p2 As Range, lastrow&, i&
AR = Cells(Rows.Count, "A").End(xlUp).Row
For Each p1 In Range(Cells(8, 1), Cells(AR, 1))
For Each p2 In Range(Cells(8, 1), Cells(AR, 1))
If p1 = p2 And Not p1.Row = p2.Row Then
Cells(p1.Row, 4) = Cells(p1.Row, 1)
Cells(p2.Row, 4) = Cells(p2.Row, 1)
End If
Next p2, p1
Range("D8:D" & Cells(Rows.Count, "D").End(xlUp).Row).RemoveDuplicates Columns:=1
lastrow = Cells(Rows.Count, "D").End(xlUp).Row
For i = lastrow To 8 Step -1
If IsEmpty(Cells(i, "D").Value2) Then
Cells(i, "D").Delete shift:=xlShiftUp
End If
Next i
End Sub