Pls help: macro to delete empty rows
Sub tract()
Dim lr As Long, lc As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lc = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
For i = lr To 2 Step -1
If WorksheetFunction.CountA(Range(Cells(i, 1), Cells(i, lc))) _
= 0 Then
Rows(i).Delete
End If
Next
End Sub
" wrote:
I have a worksheet with over 1100 rows, but with data only in every
few rows. The other rows are "empty" (ISBLANK is true). I need a
macro to delete the empty rows.
Using Record Macro, I see that if I select a row and right-click
Delete, the logic is:
Rows("2:2").Select
Selection.Delete shift:=xlUp
So in my ignorance, I tried the following, to no avail:
Dim cell As Range
For Each cell In Range("1:1144")
If cell = "" Then
cell.Rows.Delete shift:=xlUp
End If
Next
So how can I do this?
PS: Also, I forgot how to turn off/on the worksheet update. And if
I need to do this iteratively, as above, I would like to go from the
bottom up so that the shift xlUp is more efficient.
Many thanks.
|