VBA : Delete Blank rows

ssingh75

Well-known Member
Joined
Jan 5, 2012
Messages
518
Dear All,

Can anyone please let me know the Macro to delete blank rows from entire sheet...

Thanks in advance..

Susheel Singh
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
look to use something like this as I am selecting the entire used range and then deleting empty rows. Test on another sample workbook.

Sub usedR()
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
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub

 
Upvote 0
Thanks for your reply...

but looking to delete blank cells of entire columns in Excel...

Susheel Singh
 
Upvote 0
Perhaps..

Code:
Sub DeleteAllBlankCells()
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
    Range("A1").Select
End Sub
 
Upvote 0
Hi, I am using the first solution mentioned to delete rows. However, when it gets to a line containing pivot table data the CountA function is not returning a value greater than 0. I then get an error saying it is unable to delete rows containing a pivot table, and my macro ultimately fails. Any ideas for a solution that will account for rows containing pivot table data? I want these rows to be considered "used" or "not blank" so that they are not deleted.
 
Upvote 0
I downloaded a number of VBA code sets to delete blank rows and Firefly's is the only one that worked.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,705
Members
449,048
Latest member
81jamesacct

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