使用VBA删除副本 - Excel 2003 [英] Deleting Duplicates with VBA - Excel 2003

查看:137
本文介绍了使用VBA删除副本 - Excel 2003的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道可以摆脱重复的任何VBA代码。例如,在D列中,我想保留ID的第一个实例,并删除重复的文件。





注意



Greg

解决方案

好的,这应该适合你。
该例程在列C中删除所有双重ID'

  Option Explicit 


Sub DeletDuplicate()
Dim x As Long
Dim LastRow As Long
LastRow = Range(C65536)。End(xlUp).Row
对于x = LastRow到1步-1
如果Application.WorksheetFunction.CountIf(Range(C1:C& x),Range(C& x).Text)> 1然后
范围(C& x).EntireRow.Delete
结束如果
下一个x
结束Sub
pre>

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

解决方案

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

这篇关于使用VBA删除副本 - Excel 2003的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆