【发布时间】:2018-04-14 08:12:11
【问题描述】:
我正在尝试编写一个基本上查看第 13-33 行的代码,如果 B-M 列中的单元格全部为空白且 A 列不为空白,则删除整行。
我在下面编写的第一个代码仅在 B 列中的单元格为空白时删除整行,但我需要 B-M 中的所有单元格为空白才能删除整行。
Sub scheduleA()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheets("Schedule A Template").Select
Dim RowstoDelete As Long
x = 33
For RowstoDelete = Cells(x, 2).End(xlUp).Row To 13 Step -1
If (Cells(RowstoDelete, 2).Value = "0") And (Cells(RowstoDelete, 1).Value <> "") Then
Rows(RowstoDelete).Delete Shift:=xlUp
End If
Next RowstoDelete
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
我也尝试在下面的代码中以不同的方式编写它,但无法达到预期的结果。
Sub DeleteRows()
Dim i As Integer
For i = 33 To 13 Step -1
If WorksheetFunction.CountA(Range("B" & i, "M" & i)) = 0 And WorksheetFunction.CountA(Range("A" & i)) <> "" Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub
请帮忙!
【问题讨论】:
-
而不是
And WorksheetFunction.CountA(Range("A" & i)) <> ""只是做And Range("A" & i) <> ""