I am curious to know if the code below speeds up the process.
I borrowed code from jindon. I am going on the idea that the
more data you process at one time, the more it will impact
computer memory and increase the time to process, possibly reaching
a point where it takes minutes rather than seconds to complete.
With your data in every cell from A to X in 65,500 rows, the macro
took 8 seconds. The difference is that I break the data into
3 blocks and the results are entered in Sheet2.
Sub Clean_Copy()
'copy Sheet1 data, columns A - X, trimmed and cleaned
'of double spaces to Sheet2.
'This experiment breaks the data into 3 blocks to see if
'processing time can be reduced.
Dim lastRow As Long, i As Long, biteSize As Long
Dim j As Integer
Dim startTime As Date, endTime As Date, elapsedTime As Date
startTime = Now()
lastRow = ActiveSheet.UsedRange.Rows.Count
biteSize = Application.WorksheetFunction.RoundUp(lastRow / 3, 0)
With Sheets("Sheet1")
j = 1
For i = 1 To lastRow Step biteSize
Sheets("Sheet2").Range("a" & i & ":x" & (j * biteSize)).Value = _
.Evaluate("index(trim(clean(a" & i & ":x" & (j * biteSize) & ")),)")
j = j + 1
Next
End With
endTime = Now()
elapsedTime = endTime - startTime
MsgBox "Data copied in blocks" & vbCrLf & vbCrLf & _
"Start time: " & Format(startTime, "HH:MM:SS") & vbCrLf & _
"End time: " & Format(endTime, "HH:MM:SS") & vbCrLf & _
"Elapsed time: " & Format(elapsedTime, "HH:MM:SS")
End Sub
Bookmarks