my code has error "Runtime error 1004 Application defined or object define error". My excel file doesn't have protect sheets or cells. But the code still appears the error in the last line Please help me. The file contains more 900k rows, and 25 columns.
option explicit
Sub remove()
Dim i, j As Long
Dim a As Variant
Dim lsrw As Long
Dim arr()
Dim rearr()
lsrw = Sheet1.Range("A1000000").End(xlUp).Row
arr = Sheet1.Range("F2:W" & lsrw).Value
ReDim rearr(1 To UBound(arr), 1 To 18)
For i = 1 To UBound(arr())
For j = 1 To 18
If arr(i, j) <> "" Then
If Len(arr(i, j)) > 9 Then
If InStr(1, Trim(arr(i, j)), " ") > 0 Then
For Each a In Split(arr(i, j), " ")
If Len(a) >= 9 Then
rearr(i, j) = arr(i, j)
Exit For
Else: rearr(i, j) = ""
End If
Next a
Else: rearr(i, j) = arr(i, j)
End If
Else: rearr(i, j) = ""
End If
End If
Next j
Next i
Sheets("Sheet1").Range("F2").Resize(i - 1, 18) = rearr ==>error
End Sub
If i add "on error resume next" i find out that the code could excute 95k line before break
ThisWorkbook.Sheets("Sheet1").Range("F2").Resize(i - 1, 18) = rearr
. The other potential issue is that you are not resizing your range (F2
) to match the dimensions of the array. – urdearboyThisWorkbook.Sheets("Sheet1").Range("F2").Resize(lsrw - 1, 18) = rearr
– urdearboy