I'm new to excel VBA but I have now tested each part and they work correctly. What I'm trying to do is to simply delete the contents of a cell when the cells formula value is changed(no selection on entering key needed). The code is located under the sheet it runs in .
Private Sub Worksheet_Calculate()
Static MyoldVal
If Range("e6").Value <> MyoldVal Then
'Range("a1") = "start"
'MsgBox "Start"
'Call Macro_1
'Range("g6").ClearContents
MsgBox "end"
MyoldVal = Range("e6").Value
End If
End Sub
It works perfectly if the only actions are MsgBox's. Anything else and it will crash, loop or not process the rest of the code. For example, it both "start" and "stop" messages are enabled it will work fine. it and the clear contents is add in it will often work once but then it will never get to the "end".
Private Sub Worksheet_Calculate()
Static MyoldVal
If Range("e6").Value <> MyoldVal Then
'Range("a1") = "start"
'MsgBox "Start"
'Call Macro_1
'Range("g6").ClearContents
MsgBox "end"
MyoldVal = Range("e6").Value
End If
End Sub
It works perfectly if the only actions are MsgBox's. Anything else and it will crash, loop or not process the rest of the code. For example, it both "start" and "stop" messages are enabled it will work fine. it and the clear contents is add in it will often work once but then it will never get to the "end".