Excel VBA:如何从表中删除重复的值? [英] Excel VBA: How To Remove Duplicate Values From Table?

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

问题描述

彻底搜索了StackOverflow和Google,但没有找到答案.

Thoroughly searched StackOverflow and Google but didn't find answer to this.

尝试从Excel(不仅仅是电子表格)的中删除重复的值

Trying to remove duplicate values from a table in Excel (not just spreadsheet)

当前代码:

Sub RemoveDuplicates()
ActiveSheet.ListObjects("Table1").ListColumns(1).DataBodyRange.RemoveDuplicates Columns:=1, Header:=xlYes
End Sub

问题:

此代码要求在表中的每一列中的数据都必须相同,然后才能视为重复数据.(通过测试发现了这一点.)

This code requires the data in EVERY column of the table to be identical before it's considered duplicate. (Discovered this through testing).

目标:

仅在表的第1列中检查重复值,然后在发现重复项时删除整个行.我该如何实现?

Check for duplicate values only in column 1 of the table then, when duplicates are found, remove the entire row. How can I achieve this?

推荐答案

尝试以下代码:

Option Explicit

Sub RemoveDuplicates()

Dim TblRng As Range

Set TblRng = ActiveSheet.ListObjects("Table1").Range        
TblRng.RemoveDuplicates Columns:=1, Header:=xlYes

End Sub

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

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