To know the operation that triggered Change event & call iteration # to the same event
My basic requirement is that I want to know 2 things when inside a “Worksheet_Change” event :
#1 – What operation has caused this event to be triggered
#2 – Whether this is the first call or second call to this event due to that operation.
Some background:
My requirement revolves around doing an Undo operation inside the Worksheet_Change based on certain conditions. And, of course I need to do it only once for one instance of an operation. The Worksheet_Change event gets called either once or twice depending on the operation. For e.g.
Operation - # of calls made to Worksheet_Change
------------------------------------------------
Edit a cell directly – 1
Delete a cell – 1
Copy and Paste – 1
Cut and Paste – 2
Drag Drop – 2
Hence I need to know exactly the iteration # of the call to the Worksheet_Change event for that particular operation which triggered it in the first place. I am trying to use the combination of Worksheet_SelectionChange event and Worksheet_Change event and creating a counter to track the call #. Since, ideally, when we do a say for e.g., a cut-paste, after the cut is made, Worksheet_SelectionChange is called once and Worksheet_Change is called twice. So, I can use the SelectionChange event to reset the counter, or so I thought. But the following are some of the pitfalls:
A. There doesn’t seem to be any property from which we can know directly which of the above kind of operations has triggered the Change event. (The closest I saw is Application.CutCopyMode, which gives only the info of whether a cut or a copy-paste has been done and that too only inside the Worksheet_SelectionChange event).
B. Several conditions allow Excel to just get into the Worksheet_Change event without necessarily calling Worksheet_SelectionChange and hence the counter logic goes for a toss.
B.1. After a cut-paste operation (which say calls Application.Undo based on the condition), if a Redo is done, the Worksheet_Change is called without a call to Worksheet_SelectionChange event.
B.2. The same thing happens, if an operation is repeatedly done, for e.g. Copy, Paste, Paste, Paste!
So, I wanted to understand if there is any other way of getting the 2 items of information as stated above. Or by chance is there a direct attribute which can give this? For sure, Excel has all these information while it runs the event. Does it care to share
My basic requirement is that I want to know 2 things when inside a “Worksheet_Change” event :
#1 – What operation has caused this event to be triggered
#2 – Whether this is the first call or second call to this event due to that operation.
Some background:
My requirement revolves around doing an Undo operation inside the Worksheet_Change based on certain conditions. And, of course I need to do it only once for one instance of an operation. The Worksheet_Change event gets called either once or twice depending on the operation. For e.g.
Operation - # of calls made to Worksheet_Change
------------------------------------------------
Edit a cell directly – 1
Delete a cell – 1
Copy and Paste – 1
Cut and Paste – 2
Drag Drop – 2
Hence I need to know exactly the iteration # of the call to the Worksheet_Change event for that particular operation which triggered it in the first place. I am trying to use the combination of Worksheet_SelectionChange event and Worksheet_Change event and creating a counter to track the call #. Since, ideally, when we do a say for e.g., a cut-paste, after the cut is made, Worksheet_SelectionChange is called once and Worksheet_Change is called twice. So, I can use the SelectionChange event to reset the counter, or so I thought. But the following are some of the pitfalls:
A. There doesn’t seem to be any property from which we can know directly which of the above kind of operations has triggered the Change event. (The closest I saw is Application.CutCopyMode, which gives only the info of whether a cut or a copy-paste has been done and that too only inside the Worksheet_SelectionChange event).
B. Several conditions allow Excel to just get into the Worksheet_Change event without necessarily calling Worksheet_SelectionChange and hence the counter logic goes for a toss.
B.1. After a cut-paste operation (which say calls Application.Undo based on the condition), if a Redo is done, the Worksheet_Change is called without a call to Worksheet_SelectionChange event.
B.2. The same thing happens, if an operation is repeatedly done, for e.g. Copy, Paste, Paste, Paste!
So, I wanted to understand if there is any other way of getting the 2 items of information as stated above. Or by chance is there a direct attribute which can give this? For sure, Excel has all these information while it runs the event. Does it care to share