删除重复项时出错 [英] Error on remove duplicates

查看:44
本文介绍了删除重复项时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断获得

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

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

有什么想法吗?

推荐答案

我认为数组键必须以 0 开头,而不是以 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

这会导致像这样的数组

(key) = value
(0)   = 1
(1)   = 2
(2)   = 3
...
(6)   = 7

这篇关于删除重复项时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆