使用.RemoveDuplicates抛出'下标超出范围'错误

时间:2013-12-23 15:46:53

标签: excel vba excel-vba excel-2010

我有一系列可以随时间变化的单元格(目前范围是(2 to 43124, 1 to 38)),如果其中三列(2, 3 and 5列)包含相同内容,我希望删除这些单元格数据。在其他35列中没有关系。)

我正在使用:

Sub tester()

    Dim AWBN As String
    Dim ASN_2 As String
    Dim DATA_RNG As Range
    Dim LAST_ROW_NUMBER As String
    Dim LAST_COLUMN_NUMBER As Integer
    Dim LAST_COLUMN_LETTER As String

    AWBN = ActiveWorkbook.Name
    ASN_2 = ActiveSheet.Name

    LAST_COLUMN_NUMBER = Sheets(ASN_2).Cells.Find("*", Sheets(ASN_2).Range("A1"), xlFormulas, xlPart, xlByColumns, xlPrevious).Column
    LAST_COLUMN_LETTER = ColumnLetter(LAST_COLUMN_NUMBER)

    LAST_ROW_NUMBER = Sheets(ASN_2).Cells.Find("*", Sheets(ASN_2).Range("A1"), xlFormulas, xlPart, xlByRows, xlPrevious).Row

    Set DATA_RNG = Workbooks(AWBN).Sheets(ASN_2).Range("A2:" & LAST_COLUMN_LETTER & LAST_ROW_NUMBER)

    DATA_RNG.RemoveDuplicates Columns:=Array(2, 3, 5)

End Sub

它通过Set DATA_RNG行正常工作,当我在Watch窗口中检查它时,它看起来很好。范围是(1 to 43123, 1 to 38)

但是当执行.RemoveDuplicates行时,我会得到'Subscript out of range error'。使用的版本是 Excel 2010

任何想法都表示赞赏。

0 个答案:

没有答案