I have some code that does the job, but takes over twenty minutes to run. The code works on 10,000 lines of data on an excel tab and cleans it up (deleting some columns and also all teh blank rows etc and then moving it to a new tab), I do have application.screenupdating set to false and I have tried commenting different pieces of the code to figure out where the performance issue is, but I can't seem to narrow it down, any suggestions highly appreciated.
Michael
Code:
Sub cleanup()
Application.ScreenUpdating = False
Sheet2.Visible = True
Sheet2.Range("A1:F5000").ClearContents
Sheet1.Activate
DELETE_ROWS
Columns("H:O").Delete
Columns("A:B").Delete
Columns("G:G").Delete
DeleteEmptyRows Range("A1:F10000")
Cells.Select
Selection.Columns.AutoFit
Sheet2.Range("A1:F1").Value = Sheet1.Range("A1:F1").Value
Sheet2.Range("A1:F5000").Value = Sheet1.Range("A1:F5000").Value
Sheet1.Hyperlinks.Delete
ActiveSheet.DrawingObjects.Select
Selection.Delete
Range("a1").Select
Sheet1.Range("A1:F10000").ClearContents
Sheet2.Activate
Rows("1:1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Selection.Font.Bold = True
Selection.Font.Underline = xlUnderlineStyleSingle
Sheet2.Range("D2:D5000").Select
Selection.NumberFormat = "General"
Cells.Select
Selection.Columns.AutoFit
Sheet2.Range("F2:F5000").Select
Selection.NumberFormat = "0"
Cells.Select
Selection.Columns.AutoFit
ActiveSheet.UsedRange
Sheet1.Visible = xlSheetHidden
Sheet2.Range("A:f").AutoFilter
Range("a1").Select
Application.ScreenUpdating = True
End Sub
Sub DELETE_ROWS()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "B").Value) Then
ElseIf .Cells(Lrow, "B").Value = "Notes:" Then .Rows(Lrow).Delete
End If
Next
End With
End Sub
Sub DeleteEmptyRows(DeleteRange As Range)
Dim rCount As Long, r As Long
If DeleteRange Is Nothing Then Exit Sub
If DeleteRange.Areas.Count > 1 Then Exit Sub
With DeleteRange
rCount = .Rows.Count
For r = rCount To 1 Step -1
If Application.CountA(.Rows(r)) = 0 Then
.Rows(r).EntireRow.Delete
End If
Next r
End With
End Sub
Michael