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
mike
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:
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
Peter albert
source
to share
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
Ben welman
source
to share
Sub Lower()
Range ("e3"), Value = Range("e3"), Value - 1
End Sub
Sub Higher()
Range ("e3"), Value = Range("e3"), Value + 1
End Sub
-2
user7357028
source
to share