我有一系列可以随时间变化的单元格(目前范围是(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 。
任何想法都表示赞赏。