Link to home
Start Free TrialLog in
Avatar of Justin
Justin

asked on

Do Loop to delete empty rows

Hi Guys, I have a downloaded report in Excel which is 32 pages long and full of page breaks. I would like a Macro Do Loop which deletes all the blank lines. Can someone help?
Example3.xlsx
SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

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
SOLUTION
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
Select the whole area and apply an AutoFilter. Select a column that you know will be empty. Select Blanks.

Highlight the whole area and Delete Rows. It will only delete those that are visible.

Thanks
Rob H
Avatar of Justin
Justin

ASKER

Hi RGonzo, your Macro looks good, but I want to take out the headings of each page as they are just repeating. Can you adapt the Macro to delete the rows where column 11 is blank?
ASKER CERTIFIED SOLUTION
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
simply add this line either in my code above like this or in Rgonzo's code

Columns("K").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

Open in new window


Sub DeleteRows()
ActiveSheet.UsedRange.Select
'Deletes the entire row within the selection if the ENTIRE row contains no data.
Dim i As Long
'Turn off calculation and screenupdating to speed up the macro.
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
'Work backwards because we are deleting rows.
For i = Selection.Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
Columns("K").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub

Open in new window

Avatar of Justin

ASKER

It works great