I'm debugging the following code in an Excel 2007 VBA, which seems very simple. For some reason its taking about 30 minutes to process 900 rows of data. I think I have narrowed it down to some cell formatting, specifically the WrapText option. Is there something I'm missing here that can increase the performance when deleting these rows.
Sub ClearContentsOfActive()
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim NumLines
NumLines = ActiveSheet.UsedRange.Rows.Count
Range("2:" & NumLines + 3).Select
Selection.ClearContents
Selection.Delete Shift:=xlUp
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Additionally, The user was not experiencing these delays in Excel 2003, with the same code. Thanks in advance
Update
In response to the redundancy of the ClearContents line, this is the original code that was working in Excel 2003, thats why I left it. Commenting this line was one of the first things I tried, as I agreed that it may've been redundant. See below for my psuedo perfomance metrics.
Test1
Selection.ClearContents ''// Takes ~30 mins
Selection.Delete Shift:=xlUp ''// then this takes <1min
Test2
'Selection.ClearContents '// If this line is commented
Selection.Delete Shift:=xlUp ''// then this line takes ~30 mins
The reason I believe it has something to do with the WrapText feature is because when you clear the line of WrapText it performs and AutoFit operation on the row. I thought that hiding screen updates or disabling events would help.