Deleting Duplicates with VBA - Excel 2003

空扰寡人 提交于 2020-01-05 12:08:28

问题


I was wondering if anyone would know of any VBA code that would get rid of duplicates. For example, in Column D, I want to keep the first instance of the ID, and get delete the duplicate(s).

Regards

Greg


回答1:


Ok, that should work for you. That Routine delets all double Id'd in the Column C

Option Explicit


Sub DeletDuplicate()
    Dim x As Long
    Dim LastRow As Long
    LastRow = Range("C65536").End(xlUp).Row
    For x = LastRow To 1 Step -1
        If Application.WorksheetFunction.CountIf(Range("C1:C" & x), Range("C" & x).Text) > 1 Then
            Range("C" & x).EntireRow.Delete
        End If
    Next x
End Sub


来源:https://stackoverflow.com/questions/10203160/deleting-duplicates-with-vba-excel-2003

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!