错误检查应该去哪里?

所以这可能是一个非常愚蠢的问题,但我正在梳理这个代码,我需要检查单元格(A5,A7,A10)是否为空我想popup一个消息框,解释这些字段必须填充之前继续。 这是整个代码块。 我只是不知道在哪里放置错误检查。 任何帮助将是美好的。 谢谢!

'Set Variables Products = Range("B1") + 3 'Number of Products on Sheet Count = 4 'Count Used to Change the Active Cell Do While Count <= Products 'Checks if Product is Add On Only If Cells(Count, 17) = "yes" Then If Cells(Count, 5) = "grouped" Or Cells(Count, 5) = "configurable" Then 'Adds the **ADD ON ONLY** and Combines the Cells to Create Main Title Cells(Count, 7) = Trim("** ADD ON ONLY** " & Cells(Count, 2) & " " & Cells(Count, 3) & " " & Cells(Count, 6)) 'Copies Main Title To Short Description & Image Labels Cells(Count, 37) = Cells(Count, 7) 'Checks if product is Child Configurable If Cells(Count, 4) <> "simple - child config" Then 'Adds Main Title to Image Labels when Product is not Child Config Cells(Count, 56) = Cells(Count, 7) Cells(Count, 58) = Cells(Count, 7) Cells(Count, 60) = Cells(Count, 7) End If Else 'Adds the **ADD ON ONLY** and Combines the Cells to Create Main Title Cells(Count, 7) = Trim("** ADD ON ONLY** " & Cells(Count, 2) & " " & Cells(Count, 3) & " " & Cells(Count, 6) & " " & Cells(Count, 24)) 'Copies Main Title To Short Description & Image Labels Cells(Count, 37) = Cells(Count, 7) 'Checks if product is Child Configurable If Cells(Count, 5) <> "simple - child config" Then 'Adds Main Title to Image Labels when Product is not Child Config Cells(Count, 56) = Cells(Count, 7) Cells(Count, 58) = Cells(Count, 7) Cells(Count, 60) = Cells(Count, 7) End If End If 'If Product Is NOT Add On Only Else If Cells(Count, 5) = "grouped" Or Cells(Count, 5) = "configurable" Then 'Adds Combines the Cells to Create Main Title Cells(Count, 7) = Trim(Cells(Count, 2) & " " & Cells(Count, 3) & " " & Cells(Count, 6)) 'Copies Main Title To Short Description & Image Labels Cells(Count, 37) = Cells(Count, 7) 'Checks if product is Child Configurable If Cells(Count, 5) <> "simple - child config" Then 'Adds Main Title to Image Labels when Product is not Child Config Cells(Count, 56) = Cells(Count, 7) Cells(Count, 58) = Cells(Count, 7) Cells(Count, 60) = Cells(Count, 7) End If Else 'Adds Combines the Cells to Create Main Title Cells(Count, 7) = Trim(Cells(Count, 2) & " " & Cells(Count, 3) & " " & Cells(Count, 6) & " " & Cells(Count, 24)) 'Copies Main Title To Short Description & Image Labels Cells(Count, 37) = Cells(Count, 7) 'Checks if product is Child Configurable If Cells(Count, 5) <> "simple - child config" Then 'Adds Main Title to Image Labels when Product is not Child Config Cells(Count, 56) = Cells(Count, 7) Cells(Count, 58) = Cells(Count, 7) Cells(Count, 60) = Cells(Count, 7) End If End If End If 'Performs Actions on Next Cell Range Count = Count + 1 Loop End Sub 

单元格(A5,A7,A10)是空的我想popup一个消息框,说明这些字段必须填充之后才能继续。

在这种情况下,我会加在上面。

 If IsEmpty(Range("A5").Value) And IsEmpty(Range("A7").Value) And IsEmpty(Range("A10").Value) Then MsgBox ("Please fill in A5, A7, and A10 - then rerun the macro.") Exit Sub End If