当我更新到包含90,000行的新工作表时,下面的宏工作有40,000行数据但错误(1004)(到项目结束时将有大约200,000行)
我不确定为什么会收到此错误,我是否会遇到某种内置限制? (90,000行看起来并不大)
谢谢
Sub TrimAllSheetsAM()
Dim arrData() As Variant, arrReturnData() As Variant
Dim Wb As Workbook
Dim wsh As Worksheet
Dim rng As Excel.Range
Dim lRows As Long, lCols As Long, i As Long, j As Long
Set Wb = ThisWorkbook
With ActiveSheet.Cells
lCols = .Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
lRows = .Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End With
For Each wsh In Worksheets(Array("LI_Data_Resent", "RegistrationData_Resent"))
With wsh
Application.StatusBar = "Processing TRIM Worksheets " & .Name & "..."
ReDim arrData(1 To lRows, 1 To lCols)
ReDim arrReturnData(1 To lRows, 1 To lCols)
Set rng = .Range("A1").Resize(lRows, lCols)
arrData = rng.Value
For j = 1 To lCols
For i = 1 To lRows
On Error Resume Next
arrReturnData(i, j) = Trim(arrData(i, j))
On Error GoTo 0
Next i
Next j
rng.Value = arrReturnData
Set rng = Nothing
End With
Next wsh
End Sub
答案 0 :(得分:0)
您需要将变量i和j声明为Long:Dim i as Long, j as Long
以容纳65535以外的行和/或列。
这是一个常见的错误,可以在模块的最开始使用Option Explicit
语句来避免(在那里,完成了)。