2016-11-22 90 views
0

我在我的csv文件中有超過200k條客戶數據記錄。我希望能夠創建一個將比較帳戶號和產品名稱的宏。由於Account#是主要關鍵字,因此它只能與單個產品名稱綁定。VBA刪除基於兩列宏的重複行

我想我的宏給類似的輸出。現在,當我運行我的宏超過200K記錄。我只得到20行。

enter image description here

Sub DelDupl() 
Dim Rng As Range, Dn As Range, Del As Integer, Msg As Integer 
Set Rng = Range(Range("C2"), Range("C" & Rows.Count).End(xlUp)) 
For Msg = 1 To 2 
    For Del = Rng.Count To 1 Step -1 
     If Msg = 1 And Application.CountIf(Rng, Cells(Del, "C")) = 1 Then 

     End If 
     If Msg = 2 And Application.CountIf(Rng, Cells(Del, "C")) > 1 Then 
      Rows(Del).EntireRow.Delete 
     End If 
    Next Del 
Next Msg 
End Sub 

提前感謝!

+2

您是否嘗試過使用*數據>>刪除重複*? –

+0

所以你只想要剩下唯一帳號的行?爲什麼不排序,然後循環,並刪除行如果等於上面? – atclaus

+0

在你的問題中,你說*由於賬號#是一個主要鑰匙,它只能綁定到單個產品名稱。*但你真的是指*由於賬號#是一個主要鑰匙,它只能綁定到單個**客戶* * 名稱。* ?如果是這樣,你應該更新該問題,因爲目前它不掃描。 –

回答