从Excel中的列A中删除所有重复项 [英] Remove ALL duplicates from column A in Excel

查看:243
本文介绍了从Excel中的列A中删除所有重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



输入:

  John 
Jimmy
Brenda
Brenda
汤姆
汤姆
托德

输出:

  John 
Jimmy
Todd

我正在处理大量数据,Excel不是合作。似乎找不到在线解决方案。



谢谢!

解决方案

当您想要重复您的列表时,那就是确保你只有一个每个项目剩下的,你可以这样:



在Excel 2007及以上版本中,您将在数据菜单中有一个删除重复项,这将为您做。 >

在Excel 2003及更早版本中,您可以使用数据/过滤器菜单中的高级过滤器:





然后将结果复制粘贴到新表中。



您可以看到完整的程序 here。



否则写一个繁琐的宏(一个递归循环来检查该值是否存在于集合中)。可以做到这一点,但是你真的需要它吗?



但是,如果你想实际删除所有相同的条目,那么使用@ Eoins的宏就可以做这个工作,但有点修改如下:

  Option Explicit 

Sub DeleteDuplicate()
Dim x,Y As Long
Dim LastRow As Long
Dim myCell As String
LastRow = Range(A1)。SpecialCells(xlLastCell).Row
对于x = LastRow到1步骤-1
myCell = Range(A& x).Text
如果Application.WorksheetFunction.CountIf(Range(A1:A& x),myCell)> 1然后
对于Y = x到1步骤-1
如果Range(A& Y).Text = myCell Then
Range(A& Y).EntireRow。删除
结束如果
下一个Y
结束如果
下一个x
结束Sub


I am looking for a macro that can remove ALL duplicates from column A.

Input:

John
Jimmy
Brenda
Brenda
Tom
Tom
Todd

Output:

John
Jimmy
Todd

I am working with a large set of data, and Excel isn't cooperating. Can't seem to find a solution online that works.

Thanks!

解决方案

When you want to de-duplicate your list, that is make sure you only have ONE item left of each, you can to this:

In Excel 2007 and above you have a Remove Duplicates in the Data menu, which will do it for you.

In Excel 2003 and earlier you can use the Advanced Filter in the Data/Filter menu:

And then copy-paste the results in a new sheet.

You can see the full procedure here.

Otherwise it is a tedious macro to write (a recursive loop to check if the value exist in the set). It can be done, but do you really need it?

But if you want to actually delete all entries that are the same then using @Eoins's macro will do the job, but a bit modified as follows:

Option Explicit

Sub DeleteDuplicate()
    Dim x, Y As Long
    Dim LastRow As Long
    Dim myCell As String
    LastRow = Range("A1").SpecialCells(xlLastCell).Row
    For x = LastRow To 1 Step -1
        myCell = Range("A" & x).Text
        If Application.WorksheetFunction.CountIf(Range("A1:A" & x), myCell) > 1 Then
            For Y = x To 1 Step -1
                If Range("A" & Y).Text = myCell Then
                    Range("A" & Y).EntireRow.Delete
                End If
            Next Y
        End If
    Next x
End Sub

这篇关于从Excel中的列A中删除所有重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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