简体   繁体   中英

VBA Excel: How to remove duplicates in 2 columns

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)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM