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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,525
Members
448,969
Latest member
mirek8991

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