Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 717
thedeepfield Avatar asked Feb 20 '23 10:02

thedeepfield


1 Answers

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

selection.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
like image 190
El Servas Avatar answered Feb 27 '23 12:02

El Servas