Why is Columns:=aryDeDupe not the same as Columns:=(aryDeDupe)

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,910
Working to answer this thread:
https://www.mrexcel.com/forum/excel...ions-multiple-columns-without-duplicates.html

I needed a way to remove duplicates from a variable number of columns
VBA recorded for remove duplicates in H:J of columns A:J is:
Code:
ActiveSheet.Range("$A$1:$J$29").RemoveDuplicates Columns:=Array(8, 9, 10), Header:=xlYes

So worked up this code which I thought would work:

Code:
    'Check for duplicate rows in HSort Columns
    '  Can only happen if names are duplicated within an input column
    '  Build aryDeDupe  -- Array(1, 2, 3,...n)  -- to exclude iteration # column

    lLastRow = Cells(Rows.Count, lFirstWriteColumn).End(xlUp).Row
    ReDim aryDeDupe(0 To lLastHSortColumn - lFirstHSortColumn)
    lIndex = 0
    For lColumnIndex = lFirstHSortColumn To lLastHSortColumn
        aryDeDupe(lIndex) = CInt(lColumnIndex - lFirstWriteColumn + 1)
        lIndex = lIndex + 1
    Next
    ActiveSheet.Cells(1, lFirstWriteColumn).CurrentRegion.RemoveDuplicates Columns:=[COLOR="#0000FF"]aryDeDupe[/COLOR], Header:=xlYes

This code built an array that looked like this: Array(8, 9, 10), but it would not work and returned Run-time error '5': Invalid procedure call or argument

aryDeDupe matched the array structure in the recorded code and in the Locals window. I did not understand why it would not work.

I searched and found the solution in post #11 of https://www.mrexcel.com/forum/excel-questions/470729-removing-duplicates-dynamic-columns-vba-2.html

which when applied to the last line of my code added parenthesis around aryDeDupe:

Code:
ActiveSheet.Cells(1, lFirstWriteColumn).CurrentRegion.RemoveDuplicates Columns:=[COLOR="#FF0000"]([/COLOR][COLOR="#0000FF"]aryDeDupe[/COLOR][COLOR="#FF0000"])[/COLOR], Header:=xlYes

This worked, I don't understand why or how it might be applied to other Excel VBA code. An explanation or a link to same would be appreciated.

I added a post to the second thread that asked the same question I posed here, but thought it more likely would get a response if I asked directly.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
The only seemingly-applicable reference I could find stated that the parenthesis around the array forces an evaluation and allows Excel to "see" the contents of the array. There was no attribution for this somewhat opaque statement.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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