Help with Immediate Window
I think Mike meant to say the statement disables events from firing.
Depending upon the code, it is most often beneficial to disable events to
prevent continuous re-firing of the event.
Test with this code with enablevents set to True.
You will see 199 Ayo's in Immediate Window which is how many times it
fired.............seems to be a VBA limit of 199
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Debug.Print "Ayo"
'Application.EnableEvents = False
If Target.Address = "$A$1" Then
Range("a2").Value = Range("a1").Value
Else
If Target.Address = "$A$2" Then
Range("a1").Value = Range("a2").Value
Else
End If
End If
Application.EnableEvents = True
End Sub
Now run it with events disabled after clearing Immediate Window. Only one
Ayo
If you do disable events make sure you re-enable before ending sub
Best to set a trap for errors.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo ErrHandler
Application.EnableEvents = False
stuff gets done here
ErrHandler:
Application.EnableEvents = True
End Sub
Gord Dibben MS Excel MVP
On Tue, 1 Dec 2009 12:25:03 -0800, Ayo
wrote:
I have this:
Application.EnableEvents = False
in my code. And I think it is causing some problems with the way the code
works. I know there is something I can do in the Immediate Window to clear it
but I don't remember the function to use.
Any ideas.
|