在vbcancel stop sub和所有后续的subs上执行

时间:2014-03-06 20:48:40

标签: excel-vba vba excel

我有

Sub AAA()
  Call This
  Call Find
  Call That
  Call Other
 End Sub

在vbcancel上,我想停止sub和所有后续的sub,Sub That()Sub Other()not

了解vbcancel我退出了sub但后续的子程序确实运行了。

由于

编辑:我看了看并找到了答案,然后我在下一个地方发布问题后,我找到了解决方案。

End

Sub Find()

Dim blanks As Range, strMsg As String, sAddr$
Dim wordCount As Long

  wordCount = Application.WorksheetFunction.CountIf(ActiveSheet.Cells, "#NAME?")

With Worksheets(1).UsedRange

   Set blanks = .Find("#NAME?", LookIn:=xlValues, LookAt:=xlWhole)

        If Not blanks Is Nothing Then
            sAddr = blanks.Address
                Do
                     strMsg = strMsg & vbLf & blanks.Address
                      Set blanks = .FindNext(blanks)
                Loop While blanks.Address <> sAddr
                sAddr = ""

                answer = MsgBox("There are " & wordCount & " cells with #NAME? in them" & vbLf & vbNewLine & _
                  "The cell addresses are:" & strMsg & vbLf & vbLf & "They will be set to blank", vbOKCancel)

           If answer = vbCancel Then
              End
           Else
              Call Remove
           End If
        End If
  End With

End Sub

0 个答案:

没有答案