2014-03-13 110 views
1

我只是想知道如何刪除整行IF 2行在B列中具有相同的值。例如。如何刪除B列中具有相同值的整行

| A | B | 
    keep 20222 
    delete 123456 
    keep 20223 
    delete 123456 
+1

看到這個鏈接:http://辦公.microsoft.com/zh-cn/excel-help/delete-duplicate-rows-from-a-list-in-excel-HA001034626.aspx –

+0

這對我使用Excel 97不起作用。 (工作不想升級) – user3415861

+1

這種事情很容易做到沒有VBA。你能否提供更多關於你的過程和你需要完成的細節,以及什麼頻率? –

回答

0

試試這個:

Sub dural() 
    Dim N As Long, i As Long, rDel As Range 
    Dim wf As WorksheetFunction 
    Set wf = Application.WorksheetFunction 
    N = Cells(Rows.Count, "B").End(xlUp).Row 
    Set rDel = Nothing 
    For i = 1 To N 
     v = Cells(i, "B").Value 
     If wf.CountIf(Range("B:B"), v) > 1 Then 
      If rDel Is Nothing Then 
       Set rDel = Cells(i, "B") 
      Else 
       Set rDel = Union(rDel, Cells(i, "B")) 
      End If 
     End If 
    Next i 

    If rDel Is Nothing Then 
    Else 
     rDel.EntireRow.Delete 
    End If 
End Sub 
+0

非常感謝,這工作就像一個魅力! – user3415861

0

比方說您從A1

有數據此代碼將刪除重複

Sub Macro1() 
Range("A1").CurrentRegion.RemoveDuplicates Columns:=Array(1, 2), Header:=xlNo ' if you have header change xlno to xlyes 
End Sub 
相關問題