如果列中的两个连续单元格都为空,我想删除该行。
Dim rngE As Range
Set rngE = Intersect(Range("E:E"), ActiveSheet.UsedRange)
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete
以下是完成时的外观:
答案 0 :(得分:0)
'this sub routines deletes all consecutive blank rows except one from
'current sheet
'prakash b bajaj
Sub Delete_Consecutive_BlankRows_Except_One()
Dim WorkRng As Range
Dim LastUsedRow As Long
On Error Resume Next
Dim i As Long
Application.ScreenUpdating = False
LastUsedRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
Set WorkRng = Range(Cells(1, 1), Cells(LastUsedRow, 1))
For i = LastUsedRow To 1 Step -1
If Application.WorksheetFunction.CountA(WorkRng.Rows(i)) = 0 Then
If Application.WorksheetFunction.CountA(WorkRng.Rows(i - 1)) = 0 Then
WorkRng.Rows(i).EntireRow.Delete XlDeleteShiftDirection.xlShiftUp
End If
End If
Next
Cells(1, 1).Select
Application.ScreenUpdating = True
MsgBox "Done"
End Sub