Is there a bug in the value of Application.CutCopyMode

xlsat

New Member
Joined
Jun 25, 2009
Messages
34
Environment: Excel 2010 under Win 7

I was trying to identify whether a Copy-Paste operation or a Cut-Paste operation has invoked Worksheet_Change event. While trying this out, I see that though Application.CutCopyMode displays the right value in a Copy-Paste operation, the value that it has during a Cut-Paste operation seems wrong. Please see the code below for reference.
According to the help, Application.CutCopyMode property is supposed to have the following values.
> When Excel is not in Cut or Copy mode, it has value of False
> When in Copy mode, property has a value of xlCopy (which is equal to 1)
> When in Cut mode, property should have a value of xlCut (which is equal to 2)
But I am seeing that if I do a Cut & Paste operation in the respective worksheet, the line “If Application.CutCopyMode = xlCut” does not work. This is because, the property is not having the value of xlCut and instead has a value of False! The If condition works properly for a Copy & Paste operation!
Strangely, if I do an Undo, then during the Cut & Paste operation though during the forward direction it shows a value of False, while reversing during Undo it would have a value of xlCut (=2)!!! Is this a bug or am I missing something?!

Code:
Function Worksheet_Change(ByVal Target As Range)
    If Application.CutCopyMode = xlCopy Then MsgBox ("I am in COPY-Paste mode")
    If Application.CutCopyMode = xlCut Then MsgBox ("I am in CUT-Paste mode")
    If Application.CutCopyMode = False Then MsgBox ("I am NOT in Copy-Paste or Cut-Paste mode")
    'let's just print the values for reference sake
    MsgBox ("Value of xlCopy = " & xlCopy & " Value of xlCut = " & xlCut & " Value of Application.CutCopyMode = " & Application.CutCopyMode)
    'let's now do Undo. Ideally the mode before and now, should match, but let's watch what happens when we do a cut-paste op and this event is triggered
End Function
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The change will occur after the paste, at which point you are no longer in Cut mode.
 
Upvote 0
Thanks rorya. Just 2 questions in the same context -

1. Why would the Application.CutCopyMode property display the value of xlCut (=2) when a Undo Operation is done?
2. When/How else do we capture the Application.CutCopyMode property value during a Cut operation?
 
Upvote 0
1. Because you have undone the paste part.
2. If you used an event that occurred before the paste, such as a SelectionChange event for example, then you could see the xlCut value.
 
Upvote 0
Thanks a lot Rory.

I think that clarifies. Since during a cut-paste operation, the Change event is triggered twice (after pasting, yes), reportedly once for cut-operation and the other for paste operation, I was "hoping" that the .CutCopyPaste element would have xlCut value in the first parse at least. But that doesn't seem to be the case or the design...

I will see how I can use SelectionChange event along with Change event and get through my requirements.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,892
Members
449,477
Latest member
panjongshing

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top