Delete Rows

piresmdb

Board Regular
Joined
Feb 3, 2011
Messages
67
I am using the followin code to delete rows
Sub DeleteEmptyRows()
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To FinalRow
If ActiveSheet.Cells(i, 1).Value = "" Then
ActiveSheet.Cells(i, 1).EntireRow.Delete
End If
Next i

End Sub
It is working ok but deletes only one row in between two filled rows If for exaplpe in the spreadsheet there are two empti rows between A2 and A5 it deletes only A3 I have to run the macro again to delets the empty rows that were not deleted when the macro ran for the first time


Regards
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You need to loop throught the code backward (Bottom to Top)
Like this:-
Code:
For i =  FinalRow to 1 step -1
 
Upvote 0
I am using the followin code to delete rows
Sub DeleteEmptyRows()
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To FinalRow
If ActiveSheet.Cells(i, 1).Value = "" Then
ActiveSheet.Cells(i, 1).EntireRow.Delete
End If
Next i

End Sub
It is working ok but deletes only one row in between two filled rows If for exaplpe in the spreadsheet there are two empti rows between A2 and A5 it deletes only A3 I have to run the macro again to delets the empty rows that were not deleted when the macro ran for the first time

IF (and that is a big "if"), all the blanks in Column A are true blanks, that is, they are not formulas displaying the empty string (""), then here is another way to do this which should be faster than your current method...

Sub DeleteEmptyRows()
On Error Resume Next
Columns("A").SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,207,423
Messages
6,078,441
Members
446,338
Latest member
AliB

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