Adjust RemoveDuplicates code

Wil Moosa

Well-known Member
Joined
Aug 11, 2002
Messages
893
I use the following code in a few workbooks:

VBA Code:
ActiveSheet.Range("A2:Z100").RemoveDuplicates Columns:=Array(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17)

As I don’t really fully onderstand the array-thing I haven’t been able to adjust the code to my new needs.

The situation is now that I have a range of A1:AK100 where A1:AK1 = the xlheader. I want to remove every duplicate row - including A:C - based on the data in the columns D:AK. I gave it a try as follows but it did not work as I intended. Any suggestions?

CODE=vba]ActiveSheet.Range("A2:AK100").RemoveDuplicates Columns:=Array(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17)[/CODE]
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Maybe something like this...

VBA Code:
Sub test()

    Dim dataRange As Range
    Set dataRange = Range("A2:AK100")
   
    Dim duplicateColumns As Range
    Set duplicateColumns = Range("D2:AK100")
   
    ReDim arr(0 To duplicateColumns.Columns.Count - 1) As Variant
   
    Dim columnIndex As Long
    columnIndex = 4
   
    Dim arrayIndex As Long
    For arrayIndex = LBound(arr) To UBound(arr)
        arr(arrayIndex) = columnIndex
        columnIndex = columnIndex + 1
    Next arrayIndex
   
    dataRange.RemoveDuplicates Columns:=(arr), Header:=xlNo 'brackets around arr are required
   
End Sub

Hope this helps!
 
Upvote 0
Solution
Got time to check. Works great, does exactly what I asked for... and very smooth.

Thank you Domenic. Patrick, you're fired!
 
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,896
Members
449,477
Latest member
panjongshing

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