VBA: Deleting Empty Rows

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
834
Office Version
  1. 365
Platform
  1. Windows
I was needing some code that would delete all empty rows. I need it to start at Row 3 and then find the last row of data and then delete all the empty rows in that range. Thanks Excel 2010
 
Try:
Code:
Sub DeleteBlankRows()
    Application.ScreenUpdating = False
    Dim lastRow As Long
    lastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
    Dim x As Long
    For x = lastRow To 3 Step -1
        If Application.CountA(Cells(x, 1).EntireRow) = 0 Then
            Rows(x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = False
End Sub
 
Upvote 0
Try:
Code:
Sub DeleteBlankRows()
    Application.ScreenUpdating = False
    Dim lastRow As Long
    lastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
    Dim x As Long
    For x = lastRow To 3 Step -1
        If Application.CountA(Cells(x, 1).EntireRow) = 0 Then
            Rows(x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = False
End Sub

Im having a Runtime Error'1004' Delete method range class failed it then highlights Rows(x).EntireRow.Delete Thanks Jamey
 
Upvote 0
When I tried it on a dummy file, it worked for me. It would be helpful if I could see how your data is organized. Is there any way you could upload your file to a site such as www.box.com? It will give you a link to the uploaded file which you could post here.
 
Upvote 0
Try this assuming column A can be used to determine a blank row.

Code:
Sub DeleteEmptyrows()
Range("A3:A" & Rows.Count).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End sub
 
Upvote 0

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