thedeepfield
thedeepfield

Reputation: 6196

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)

Upvotes: 4

Views: 34612

Answers (1)

El Servas
El Servas

Reputation: 98

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

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

Upvotes: 8

Related Questions