Macro to Delete Empty Rows on Multiple Sheets

squeakums

Well-known Member
Joined
May 15, 2007
Messages
823
Office Version
  1. 365
I have this macro but I want to edit several sheets within the code and so it is telling me to modify the code for each. Is there a simple code that I can write per spreadsheet this edits within the macro to delete any rows that are empty data? Below is the one I am currently using.

VBA Code:
Dim LastRowIndex As Integer
    Dim RowIndex As Integer
    Dim UsedRng As Range
 
    Set UsedRng = ActiveSheet.UsedRange
    LastRowIndex = UsedRng.Row - 1 + UsedRng.Rows.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
 
    Application.ScreenUpdating = True
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try:
VBA Code:
Sub DeleteRows()
    ActiveSheet.Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
 
Upvote 0
It works only when there spaces; but errors out when there are no spaces to delete. I would like for it to continue with the process if nothing is found.
 
Upvote 0
Try:
VBA Code:
Sub DeleteRows()
    Dim LastRow As Long
    LastRow = Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If WorksheetFunction.CountA(Range("A1:A" & LastRow)) < LastRow Then
        Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End If
End Sub
 
Upvote 0
Try the macro in Post #4.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top