Problem with deleting "empty" rows

Stringt

New Member
Joined
Feb 18, 2002
Messages
35
I have a problem with deleting balnk rows using VBA. I have the following code that works on one page of my WB. I have used formula's on sheet 2 to extract only the information I want to keep. I then want to delete all blank rows but the VBA doesn't work.

I have tried copying the sheet and pasting values only but for some reason the CountA function is counting empty cells and thus the macro is not working. So if I do Counta on an "empty" row it retuns 47!! Help...

VBA code:

Sub del()

With Application

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
End With

End Sub
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
L

Legacy 11273

Guest
I presume that your formulas are putting an empty string "" in the cells .
Cells containing this are not treated as blank cells by the COUNTA function.

One alternative is to use the COUNTBLANK function (which treats cells as blank containing "" or cells with formulas that return "") :-

For i = Selection.Rows.Count To 1 Step -1
If WorksheetFunction.CountBlank(Selection.Rows(i)) = 256 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
 

Watch MrExcel Video

Forum statistics

Threads
1,122,670
Messages
5,597,483
Members
414,146
Latest member
marginmakerb

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
Top