【发布时间】:2020-10-04 10:51:08
【问题描述】:
我只想检查一个范围内是否有空行,例如,如果 S28 为“KO”或“OK”,则上面的行 (offset(-1,0) 不应为空。
如果为空白,则该功能应停止。
如果一个单元格是空白的,而上面的单元格是空白的,那没关系。
S中的每个单元格都有一个公式,countif函数。
代码说有空行,事实并非如此。我删除了 S28 中的数据,您可以在图片上看到。因此,不应该有 msgbox。第一行检查在 S12 中。
Private Function detecht_empty_rows() As Boolean
Call DefineVariables
Dim lrowS As Long
Dim cell As Range
Dim startingcell As String
lrowS = shInput.cells(Rows.Count, 19).End(xlUp).Row
For Each cell In shInput.Range("S13" & ":" & "S" & lrowS)
startingcell = cell.Address
If cell.Text = "" And IsEmpty(cell.Offset(-1, 0)) = True Then
ElseIf cell.Text = "OK" Or cell.Text = "KO" And IsEmpty(cell.Offset(-1, 0)) = True Then
MsgBox "Please remove the blank rows"
Exit Function
End If
Next cell
End Function
【问题讨论】:
-
两个 KO 之间的界限对我来说看起来很空旷。另外,您的 if 语句看起来很奇怪,因为 If 子句没有代码。
-
我特意放了这张图片,在我运行代码的地方,我删除了空单元格。这张图片说明了我的代码目标。