正在跳过Excel VBA IF语句

时间:2018-06-14 16:04:54

标签: excel vba if-statement

我有两个If语句在下面跟随。第一步检查上一步是否标记为带有“X”的完成,并根据需要退出宏。第二个If语句检查该步骤是否已经运行。这显示“继续?”问题,但选择“否”不会结束宏。

If Range("D4").Value = "" Then
Dim response As VbMsgBoxResult
response = MsgBox("Previous step is not marked as complete. Proceed?", vbYesNo)
If response = vbNo Then
    Exit Sub
End If
End If

If Range("D4").Value = "X" Then
Dim response2 As VbMsgBoxResult
response2 = MsgBox("Current step is already marked as complete, proceed?", vbYesNo)
If response = vbNo Then
    Exit Sub
End If
End If

Set Range1 = Sheets("Latest Open QNs Report Data").ListObjects("OpenQns").DataBodyRange.Offset(0, 1)
Set Range1 = Range1.Resize(Range1.Rows.Count, Range1.Columns.Count - 1)
Range1.ClearContents

Sheets("Instructions").Select
Range("D5", "D5").Value = "X"

1 个答案:

答案 0 :(得分:2)

你想要一个拼写错误:

If response2 = vbNo Then ...

或将response2 = MsgBox(...)重命名为response = ...