S
Stuart
I've searched Google for this, but without success.
May have missed it, so a link would be appreciated.
I need to search a range (typically a few columns, but
many more rows)....say "A1:H5000", for rows that are
empty.
I cannot just delete every empty row. I have to preserve
one empty row. So when I find an empty row, I need to
find if there are any adjacent empty rows, and if so how
many. Then delete all but one.
I have found this (originally from Ron, then amended by
Tom) and wonder if an amendment to this code would
be the best approach:
Sub DeleteEmptyRowsRon()
Dim rng As Range, LastRow As Long, r As Integer
'JW
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.CountA(Rows(r)) = 0 Then 'Rows(R).Delete
If rng Is Nothing Then
Set rng = Rows(r)
Else
Set rng = Union(rng, Rows(r))
End If
End If
Next r
rng.Delete
End Sub
I think I can see how Union might be used to create a
contiguous set of empty rows to be deleted, but that's
my limit.
Any help much appreciated.
Regards.
May have missed it, so a link would be appreciated.
I need to search a range (typically a few columns, but
many more rows)....say "A1:H5000", for rows that are
empty.
I cannot just delete every empty row. I have to preserve
one empty row. So when I find an empty row, I need to
find if there are any adjacent empty rows, and if so how
many. Then delete all but one.
I have found this (originally from Ron, then amended by
Tom) and wonder if an amendment to this code would
be the best approach:
Sub DeleteEmptyRowsRon()
Dim rng As Range, LastRow As Long, r As Integer
'JW
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.CountA(Rows(r)) = 0 Then 'Rows(R).Delete
If rng Is Nothing Then
Set rng = Rows(r)
Else
Set rng = Union(rng, Rows(r))
End If
End If
Next r
rng.Delete
End Sub
I think I can see how Union might be used to create a
contiguous set of empty rows to be deleted, but that's
my limit.
Any help much appreciated.
Regards.