I have an excel table (reportInfo(0)).ListObjects(reportInfo(1)) that I am trying to remove duplicates from. To do this, I need to call out an array with the columns with duplicate values. In this case, I need to remove any rows in which columns 1 and 3 are the same. My code is as follows:
When I run it this way, I get a type mismatch error. If I change the remove duplicates code to either of the following, it works:
Or:
I can't use the second option because the number of columns that I want to use to remove duplicates will not always be the same.
VBA Code:
Dim columnsToDuplicate As Variant
columnsToDuplicate = Array(1, 3)
'REMOVE DUPLICATES
table.Range.RemoveDuplicates Columns:=Array(columnsToDuplicate), Header:=xlYes
When I run it this way, I get a type mismatch error. If I change the remove duplicates code to either of the following, it works:
VBA Code:
'REMOVE DUPLICATES
table.Range.RemoveDuplicates Columns:=Array(1, 3), Header:=xlYes
Or:
VBA Code:
'REMOVE DUPLICATES
table.Range.RemoveDuplicates Columns:=Array(columnsToDuplicate(0), columnsToDuplicate(1) ), Header:=xlYes
I can't use the second option because the number of columns that I want to use to remove duplicates will not always be the same.