Link to home
Start Free TrialLog in
Avatar of Ray Erden
Ray ErdenFlag for United States of America

asked on

Delete macro for blank rows/column on selected tabs

Assume that there are two tabs with data on a file and each tab has a different number of rows and columns populated. What I need to do is to delete all the rest of the blank rows and columns from those tabs via a macro run.  Can I get a working sample for that please?  Thank you in advance.
Avatar of byundt
byundt
Flag of United States of America image

You might try a macro like this to delete your blank rows and columns. It works on the active worksheet.
Sub DeleteEmptyRowsAndColumns()
Dim rg As Range
Dim i As Long, j As Long
Application.ScreenUpdating = False
Set rg = ActiveSheet.UsedRange
For i = rg.Rows.Count To 1 Step -1
    If Application.CountA(rg.Rows(i)) = 0 Then rg.Rows(i).Delete
Next
For j = rg.Columns.Count To 1 Step -1
    If Application.CountA(rg.Columns(j)) = 0 Then rg.Columns(j).Delete
Next
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ray Erden

ASKER

Thank you!