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?!
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