Dim ws As Worksheet
Const FixCols = True 'True to perform Column Deletion
Const FixRows = False 'True to perform Row Deletion
Const RowInterval = 100 'How many rows to delete at each command
Const ShowWork = True 'Indicates if screen should update [False=faster]
Sub FixIt()
If Not ShowWork Then Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set ws = ThisWorkbook.Sheets(1)
UsedC = ws.UsedRange.Cells.Count
xlUR = ws.UsedRange.Rows.Count
xlUC = ws.UsedRange.Columns.Count
LDR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
LDC = ws.Range(Cells(1, Columns.Count).Address).End(xlToLeft).Column
If FixCols + FixRows = 0 Then
ReportToDebug ws, "Just Reporting"
End If
If FixCols Then
ReportToDebug ws, "BEFORE Columns"
ws.Columns(xlUC + 1).ColumnWidth = 2
ws.Columns(xlUC + 1).Interior.ColorIndex = 1
For ColIdx = xlUC To (LDC + 1) Step -1
ws.Cells(1, ColIdx).Activate
Application.StatusBar = "Col: " & RowIdx
ws.Columns(ColIdx).Delete
DoEvents
Next ColIdx
ws.Columns(LDC + 1).Delete
ReportToDebug ws, "AFTER Columns"
End If
If FixRows Then
ReportToDebug ws, "BEFORE Rows"
For RowIdx = xlUR To (LDR + 1) Step -RowInterval
If RowIdx < LDR Then Exit For
ws.Cells(RowIdx, 1).Activate
Application.StatusBar = "Row: " & RowIdx
ws.Rows(RowIdx - (RowInterval - 1)).Resize(RowInterval).Delete
DoEvents
Next RowIdx
ReportToDebug ws, "AFTER Rows"
End If
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Sub ReportToDebug(ws As Worksheet, desc As String)
'Reports worksheet range used
Debug.Print "========================"
Debug.Print desc
UsedC = ws.UsedRange.Cells.Count
xlUR = ws.UsedRange.Rows.Count
xlUC = ws.UsedRange.Columns.Count
LDR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
LDC = ws.Range(Cells(1, Columns.Count).Address).End(xlToLeft).Column
Debug.Print "xl Used Cells: "; Format(UsedC, "#,##0")
Debug.Print "xl Used Rows: "; Format(xlUR, "#,##0")
Debug.Print "xl Used Cols: "; Format(xlUC, "#,##0")
Debug.Print "dat Used Rows: "; Format(LDR, "#,##0")
Debug.Print "dat Used Cols: "; Format(LDC, "#,##0")
End Sub