Sub TEST()
Dim xR As Range, xDic, xU As Range, N&, V&, XX As Range
Set xDic = CreateObject("Scripting.Dictionary")
For Each xR In Range([A2], [A65536].End(xlUp))
N = xDic(xR.Value)
If N = 0 Then xDic(xR.Value) = xR.Row: GoTo 101
V = Application.CountA(Range(xR(1, 3), xR(1, 7)))
Set XX = xR
If V > 0 Then Set XX = Range("A" & N): xDic(xR.Value) = xR.Row
If xU Is Nothing Then Set xU = XX Else Set xU = Union(xU, XX)
101: Next
If Not xU Is Nothing Then xU.EntireRow.Delete
End Sub
Sub TEST()
Dim xR As Range, xDic, xU As Range, N&, V&, XX As Range
Set xDic = CreateObject("Scripting.Dictionary")
For Each xR In Range([A2], [A65536].End(xlUp))
N = xDic(xR.Value)
If N = 0 Then xDic(xR.Value) = xR.Row: GoTo 101
'_第一次遇見你,請留下您的電話號碼(列號):xDic(xR.Value) = xR.Row
'_N = 0,表示第一次的相遇,記住列號後,略過下方的語句(GoTo 101)
V = Application.CountA(Range(xR(1, 3), xR(1, 7)))
'_第二次(及以後)遇見你,請問你口袋有沒有錢(檢查非空格)
If V = 0 Then Set XX = xR
'_如果沒有錢,你這次的新電話號碼我不想留:Set XX = xR
If V > 0 Then Set XX = Range("A" & N): xDic(xR.Value) = xR.Row
'_如果有錢,上次留的電話作廢:Set XX = Range("A" & N)
'_換留這次的新電話號碼:xDic(xR.Value) = xR.Row
If xU Is Nothing Then Set xU = XX Else Set xU = Union(xU, XX)
'_將要作廢的電話號碼集中起來
101: Next
If Not xU Is Nothing Then xU.EntireRow.Delete
'_一次刪去作廢電話號碼
End Sub作者: c_c_lai 時間: 2016-7-24 17:43