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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,780
Messages
5,833,661
Members
430,222
Latest member
Nickkarl

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