PDA

View Full Version : Solved: Delete empty rows



justdriving
09-17-2011, 01:50 PM
I know that there are certain rows which don't have any value in any cell.
I am trying to delete an empty row.

How can I correct this program in VBA: -


Sub test()

For rownum = 1 to EndofRowCalculatedFromA65536
For colnum = 1 to 256

If Cells(rownum, colnum) <> vbnullstring Then

Else
Delete Entirerow
End If

Next colnum
Next rownum

End Sub

Bob Phillips
09-17-2011, 02:00 PM
Sub test()
Dim Lastrow As Long
Dim i As Long

Application.ScreenUpdating = False

With ActiveSheet

Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = Lastrow To 2 Step -1

If Application.CountA(.Rows(i)) = 0 Then

.Rows(i).Delete
End If

Next i
End With

Application.ScreenUpdating = True
End Sub

justdriving
09-17-2011, 03:53 PM
Yes, it worked. Many thanks, Bob