Unable to execute macro in break mode

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

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

      

I am getting the following error when I click on a (numeric) cell and try to run a macro:

Cannot Execute in Break Mode

      

What am I missing?

+3


source to share


3 answers


You are already running the macro and somehow stopped running it (for example, due to an unhandled error or because you pressed Ctrl- Breakduring execution). In this state, you cannot execute another macro.

In the Visual Basic editor, you need to click the Stop button: enter image description here



Then you can run the macro.

If you want to understand where the current execution stopped, right-click the code and choose Show Next Report. If you then click F8, you can step through the code. F5continues execution.

+10


source


And you have to 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

      

+2


source


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

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

      

-2


source







All Articles