循环 VBA 语句以在继续 sub 之前检查空单元格



我是VBA的新手。我将如何更改以下代码以检查单元格 Q1:Q5 而不仅仅是 Q1。另外,是否可以暂时突出显示空的单元格?

If ActiveSheet.Range("Q1").Value = "" Then
    Answer = MsgBox("You have not entered all of the required details.", vbCritical, "Error")
Exit Sub
End If

要突出显示空的单元格,请使用条件格式(无需代码即可应用)

参见黛布拉·达格利什的网站

代码问题

Sub CellCheck()
Dim rng1 As Range
Set rng1 = Range("Q1:Q5")
If Application.CountA(rng1) <> rng1.Cells.Count Then _
    Answer = MsgBox("You have not entered all of the required details.", vbCritical, "Error")
End Sub

相关内容

最新更新