删除重复项时出错

时间:2017-03-03 09:27:42

标签: vba excel-vba excel

我继续得到

  

无效的过程调用或参数 - 运行时错误'5'

当我在工作表上删除重复项时。

 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

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

数组键需要从0开始,而不是1我认为。

 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

这会产生类似

的数组
(key) = value
(0)   = 1
(1)   = 2
(2)   = 3
...
(6)   = 7
相关问题