How can I pass a variable to the Columns parameter of the RemoveDuplicates method?
'Option Base 1
'Dim Col2Rmv() As Long
'Col2Rmv(1)=1
'Col2Rmv(2)=3
These all work but they all involve hardcoding the Columns parameter:
'Range("A1:G10").RemoveDuplicates Columns:=1 'consider only one column
'Range("A1:G10").RemoveDuplicates Columns:=VBA.Array(1) 'consider only one column
'Range("A1:G10").RemoveDuplicates Columns:=VBA.Array(1,3,7) 'consider multiple columns simultaneously
'Range("A1:G10").RemoveDuplicates Columns:=VBA.Array(Col2Rmv(1), Col2Rmv(2)) 'consider multiple columns
How can I pass the array Col2Rmv directly to the Columns parameter such as this (but it doesn't work):
'Range("A1:G10").RemoveDuplicates Columns:=Col2Rmv
Col2Rmv might be this:
'Col2Rmv(1)=1
'Col2Rmv(2)=3
or:
'Col2Rmv(1)=1
'Col2Rmv(2)=3
'Col2Rmv(3)=7
or some other list of column numbers not predetermined.
I've tried several different things but none have worked properly to where all columns of interest are considered simultaneously.
Is there a way to create a loop and add individual values to an Array and then pass that to the Columns parameter?
What I've tried:
'Dim Col2Rmv() As Variant
populate Col2Rmv with column numbers of interest
'Range("A1:G10").RemoveDuplicates Columns:=Col2Rmv
'Range("A1:G10").RemoveDuplicates Columns:=(Col2Rmv)
'Range("A1:G10").RemoveDuplicates Columns:=Evaluate(Col2Rmv)
'Range("A1:G10").RemoveDuplicates Columns:=Col2Rmv(1)
'Range("A1:G10").RemoveDuplicates Col2Rmv
'Option Base 1
'Dim Col2Rmv() As Long
'Col2Rmv(1)=1
'Col2Rmv(2)=3
These all work but they all involve hardcoding the Columns parameter:
'Range("A1:G10").RemoveDuplicates Columns:=1 'consider only one column
'Range("A1:G10").RemoveDuplicates Columns:=VBA.Array(1) 'consider only one column
'Range("A1:G10").RemoveDuplicates Columns:=VBA.Array(1,3,7) 'consider multiple columns simultaneously
'Range("A1:G10").RemoveDuplicates Columns:=VBA.Array(Col2Rmv(1), Col2Rmv(2)) 'consider multiple columns
How can I pass the array Col2Rmv directly to the Columns parameter such as this (but it doesn't work):
'Range("A1:G10").RemoveDuplicates Columns:=Col2Rmv
Col2Rmv might be this:
'Col2Rmv(1)=1
'Col2Rmv(2)=3
or:
'Col2Rmv(1)=1
'Col2Rmv(2)=3
'Col2Rmv(3)=7
or some other list of column numbers not predetermined.
I've tried several different things but none have worked properly to where all columns of interest are considered simultaneously.
Is there a way to create a loop and add individual values to an Array and then pass that to the Columns parameter?
What I've tried:
'Dim Col2Rmv() As Variant
populate Col2Rmv with column numbers of interest
'Range("A1:G10").RemoveDuplicates Columns:=Col2Rmv
'Range("A1:G10").RemoveDuplicates Columns:=(Col2Rmv)
'Range("A1:G10").RemoveDuplicates Columns:=Evaluate(Col2Rmv)
'Range("A1:G10").RemoveDuplicates Columns:=Col2Rmv(1)
'Range("A1:G10").RemoveDuplicates Col2Rmv