VBA Excel:如何删除两列中的重复项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12078529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 13:51:21  来源:igfitidea点击:

VBA Excel: How to remove duplicates in 2 columns

excelvbaduplicatesrange

提问by thedeepfield

I have the following below, but I'm having issues with the syntax. I want to set the current selection as a range, and I want to remove duplicates from that selection. How can I do this?

我有以下内容,但语法有问题。我想将当前选择设置为一个范围,并且我想从该选择中删除重复项。我怎样才能做到这一点?

'remove duplicates
Columns("B:C").Select
Dim duplicates As Range
Set duplicates = Selection
ActiveSheet.duplicates.RemoveDuplicates(Columns:=Array(1, 2), Header:=xlYes)

回答by El Servas

Remove the parenthesis when calling RemoveDuplicates if the function is not returning any value, like this:

如果函数没有返回任何值,则在调用 RemoveDuplicates 时删除括号,如下所示:

selection.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes