JackDanIce
Well-known Member
- Joined
- Feb 3, 2010
- Messages
- 9,922
- Office Version
- 365
- Platform
- Windows
Hi,
Curious about fastest way to clear data from a range, I created following and resulting output:
rng.value = vbNullString appears to be the fastest method but is there anything I haven't considered or overlooked? Any suggestions that are faster?
TIA,
Jack
Curious about fastest way to clear data from a range, I created following and resulting output:
Code:
Sub testrun()
Dim x As Long
For x = 1 To 3
testtime x
Next x
Debug.Print ""
End Sub
Sub testtime(ByRef testvar As Long)
Dim st As Double
Dim rng As Range
st = Timer
With Sheets("Sheet3")
.Cells(1, 1).Resize(Rows.Count * 0.0005, Columns.Count * 0.25).Value = "xx"
Set rng = .Cells(2, 1).Resize(LastRow(Sheets("Sheet3")) - 1, LastCol(Sheets("Sheet3")))
End With
Select Case testvar
Case Is = 1: rng.ClearContents
Case Is = 2: rng.Value = vbNullString
Case Is = 3: rng.Value = Evaluate("IF(LEN(" & rng.Address & "), """")")
End Select
Set rng = Nothing
Debug.Print "Testvar: " & testvar & " " & Round(Timer - st, 4) & " seconds"
End Sub
Code:
Testvar: 1 0.6289 seconds
Testvar: 2 0.5078 seconds
Testvar: 3 2.6914 seconds
Testvar: 1 0.5898 seconds
Testvar: 2 0.5117 seconds
Testvar: 3 2.707 seconds
Testvar: 1 0.6289 seconds
Testvar: 2 0.5078 seconds
Testvar: 3 2.7461 seconds
TIA,
Jack