1

I keep on getting an

invalid procedure call or argument - Run-Time ERROR '5'

when I remove duplicates on a sheet.

 With sh.Range("$A$1:G" & Sh.Range("A1").SpecialCells(xlCellTypeLastCell).Row)
        ReDim iArray(1 To .Columns.Count)
        For i = 1 To UBound(iArray)
            iArray(i) = i
        Next i
        .RemoveDuplicates Columns:=(iArray), header:=xlYes
 end With

Any ideas?

Community
  • 1
  • 1
Lowpar
  • 897
  • 10
  • 31

1 Answers1

1

The array keys needs to start with 0 not with 1 I think.

 With sh.Range("$A$1:G" & Sh.Range("A1").SpecialCells(xlCellTypeLastCell).Row)
        ReDim iArray(0 To .Columns.Count - 1)
        For i = 0 To UBound(iArray)
            iArray(i) = i + 1
        Next i
        .RemoveDuplicates Columns:=(iArray), header:=xlYes
 end With

This results in an array like

(key) = value
(0)   = 1
(1)   = 2
(2)   = 3
...
(6)   = 7
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73