为什么这个程序忽略了“退出子” [英] Why this program ignores "exit sub"
本文介绍了为什么这个程序忽略了“退出子”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我执行此代码时。它实际上忽略了第一个msgbox之后的exit子,并显示下一个msgbox,无论条件是true还是false。请帮我解答答案
When i execute this code.Its actually ignore the exit sub after the 1st msgbox and display the next msgbox whether the condition is true or false. Please help me with the answer
Sub Insertnex()
Dim Name As String
Dim State As String
Dim Newdate As Date
Dim ButtonClicked As VbMsgBoxResult
GuessAgain:
Name = InputBox("Please enter the name")
Sheet1.Activate
On Error GoTo Namenotfound
Range("B3:B15").Find(Name).Select
On Error GoTo 0
Name = ActiveCell.Value
State = ActiveCell.Offset(0, 1).Value
On Error GoTo InvalidDate
Date = ActiveCell.Offset(0, 2).Value
MsgBox Name & " stays in " & State & " she is staying there since " & Date
Exit Sub
Namenotfound:
ButtonClicked = MsgBox(Name & " was not found in the list.")
If ButtonClicked = vbRetry Then Resume GuessAgain
Exit Sub
InvalidDate:
MsgBox Date & "Was in wrong formate"
End Sub
< b>我尝试了什么:
我试图找出问题,但我无法解决这个问题
What I have tried:
I tried to figure out the issue but i am unable to solve this
推荐答案
为了能够获得vbRetry
代码,您需要正确设置MsgBox
,例如:
To be able to getvbRetry
code, you need to properly set upMsgBox
, for example:
Sub Test()
Dim ButtonClicked As Long
ButtonClicked = vbRetry
Do While ButtonClicked = vbRetry
ButtonClicked = MsgBox("Click Cancel to exit the loop", vbRetryCancel, "Not found...")
Loop
End Sub
随意根据需要更改代码。
Feel free to change the code to your needs.
这篇关于为什么这个程序忽略了“退出子”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文