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
Visual Basic ClassicMicrosoft Excel

Avatar of undefined
Last Comment
Justin
SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Professor J
Professor J

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Justin
Justin

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Professor J
Professor J

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
Justin

ASKER

It works great
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo