Cannot execute macro in Break Mode

隐身守侯 提交于 2019-12-07 02:57:47

问题


I am trying to write a simple macro to add 1 to the cell's current value:

Sub add()
    MsgBox Selection.Value
    Selection.Value = Selection.Value + 1
End Sub

I receive the following error message when I click a (numeric) cell and try to run the macro:

Cannot Execute in Break Mode

What am I missing?


回答1:


You are already executing a macro and somehow stopped its execution (e.g. due to an unhandled error or because you pressed Ctrl-Break during the execution). In this state, you cannot execute another macro.

In the Visual Basic Editor, you need to press the Stop button:

Then you can run the macro.

If you want to understand where the current execution is stopped, right click the code and select Show Next Statement. If you then press F8 you can step through the code. F5 continues the execution.




回答2:


And you should check if the value in the cell is numeric. Example

Sub add()
    If IsNumeric(Selection.Value) Then
        Selection.Value = Selection.Value + 1
    Else
        MsgBox ("Not a value selected")
    End If
End Sub



回答3:


Sub Lower()
    Range ("e3"), Value = Range("e3"), Value - 1
End Sub

Sub Higher()
    Range ("e3"), Value = Range("e3"), Value + 1
End Sub


来源:https://stackoverflow.com/questions/14934433/cannot-execute-macro-in-break-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!