Worksheet_Change: Caused by User or VBA?

Nick Burns

Member
Joined
May 24, 2017
Messages
162
Reaction score
0
Points
16
Excel Version(s)
Office 365
Is there a way to determine if the User is editing the worksheet or if VBA is manipulating it?
Both actions cause the Worksheet_Change event to fire, but I want certain actions to happen when it's being changed by the user vs VBA.

Thanks
 
I thought that Application.Caller might come to the rescue but it doesn't.
My first thoughts on this are to use a workaround involving a global variable:
You get the vba which is about to do something on a sheet to set a global variable (let's call it VBAisDoingThis) to True, then when it has finished making changes to the sheet set it to False.
In the Sheet_Change event handler, include a statement which looks at the global variable VBAisDoingThis to determine whether VBA is doing this or a user is doing it.

I have used this sort of thing to be more selective than the blanket Application.EnableEvents=False when deciding what event handlers do.
 
Back
Top