Remove Duplicates Multiple Columns

trough

Board Regular
Joined
Oct 26, 2010
Messages
55
I cannot figure out why I am getting a "Subscript out of range" error with this line:

WS.Range(Cells(1, 1), Cells(5, 3)).RemoveDuplicates Columns:=Array(2, 3), Header:=xlNo
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
More:

This works:
Range(Cells(1, 1), Cells(5, 3)).RemoveDuplicates Columns:=2, Header:=xlNo

But this doesn't:
Range(Cells(1, 1), Cells(5, 3)).RemoveDuplicates Columns:=Array(2), Header:=xlNo

Why?
 
Upvote 0
why?
because of this

try like this bro
VBA Code:
Sub www()

Dim ws As Worksheet
Dim ar As Variant
Set ws = ThisWorkbook.Sheets("Sheet2")

ar = [{1,2}]

Range(Cells(1, 1), Cells(5, 3)).RemoveDuplicates ar(1), Header:=xlNo

End Sub
 
Upvote 0
Solution
But how would I build a string of multiple columns, Ex. MyStr="1,3" -> ar="[{" & MyStr & "}]", that would be accepted by the RemoveDuplicates command? It doesn't seem to like a string.
 
Upvote 0
This code will fail if the sheet is not the active sheet
VBA Code:
WS.Range(Cells(1, 1), Cells(5, 3)).RemoveDuplicates Columns:=Array(2, 3), Header:=xlNo
it should be
VBA Code:
WS.Range(WS.Cells(1, 1), WS.Cells(5, 3)).RemoveDuplicates Columns:=Array(2, 3), Header:=xlNo
 
Upvote 0

Forum statistics

Threads
1,223,877
Messages
6,175,138
Members
452,614
Latest member
MRSWIN2709

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top