I tried using .xlsb file so as to execute it in all different workbooks, but keep getting Error 400, even though my Macro is working for that particular file. I wrote this simple code to delete the empty rows and columns in the workbook.
Sub RepeatTask()
Dim xSh As Worksheet
Application.ScreenUpdating = False
For Each xSh In Worksheets
xSh.Select
Call task
Next
Application.ScreenUpdating = True
End Sub
Sub task()
Dim LastColumnIndex As Integer
Dim LastRowIndex As Integer
Dim RowIndex As Integer
Dim ColumnIndex As Integer
Dim UsedRng As Range
Set UsedRng = ActiveSheet.UsedRange
LastRowIndex = UsedRng.Row - 1 + UsedRng.Rows.Count
LastColumnIndex = UsedRng.Column - 1 + UsedRng.Columns.Count
Application.ScreenUpdating = False
For RowIndex = LastRowIndex To 1 Step -1
If Application.CountA(Rows(RowIndex)) = 0 Then
Rows(RowIndex).Delete
End If
Next RowIndex
For ColumnIndex = LastColumnIndex To 1 Step -1
If Application.CountA(Columns(ColumnIndex)) = 0 Then
Columns(ColumnIndex).Delete
End If
Next ColumnIndex
Application.ScreenUpdating = True
End Sub