Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 188
Default Worksheet_Change Event - Macro kills copy and paste


Hi All,

I have a macro running upon a Worksheet_Change and Worksheet_SelectionChange
event from within a worksheet code (not a module).

When a change is made to the worksheet, which is a filtered list, it calls a
sub which checks which columns are filtered and changes the background
colour to make it easier to see, or changes it back to no fill if the filter
was removed.

However, if a user tries to copy and paste from one cell to another, when
they move the cell pointer up a cell (say), one of the events is triggered
and by the time the macro has run, the contents of the cell that was copied
has been lost and paste is ineffective.

I am wondering if there is some way for me to check in the event procedure
whether the user has tried to copy something, and if so, then not call the
macro?

Thanks in advance for any help you can render,

Alan.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Worksheet_Change Event - Macro kills copy and paste

Hi Alan,

The value of Application.CutCopyMode will tell you whether a user has a
cut or copy operation in progress when your event procedure fires, something
like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.CutCopyMode = 0 Then
''' User hasn't copied anything,
''' run your macro here.
End If
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Alan" wrote in message
...

Hi All,

I have a macro running upon a Worksheet_Change and

Worksheet_SelectionChange
event from within a worksheet code (not a module).

When a change is made to the worksheet, which is a filtered list, it calls

a
sub which checks which columns are filtered and changes the background
colour to make it easier to see, or changes it back to no fill if the

filter
was removed.

However, if a user tries to copy and paste from one cell to another, when
they move the cell pointer up a cell (say), one of the events is triggered
and by the time the macro has run, the contents of the cell that was

copied
has been lost and paste is ineffective.

I am wondering if there is some way for me to check in the event procedure
whether the user has tried to copy something, and if so, then not call the
macro?

Thanks in advance for any help you can render,

Alan.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Worksheet_Change Event - Macro kills copy and paste

Rob Bovey wrote:
Hi Alan,

The value of Application.CutCopyMode will tell you whether a user has a
cut or copy operation in progress when your event procedure fires, something
like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.CutCopyMode = 0 Then
''' User hasn't copied anything,
''' run your macro here.
End If
End Sub

Thanks. That is good to know. Though I haven't had any problem with the
change event and copy/pasting, I have needed to know when a copy/paste
operation happened to clear comments and to speed up some functions.
Have been using this:

' If value was pasted, delete comments.
If ((ActiveCell.Row = Target.Row) And (ActiveCell.Column =
Target.Column)) Then
Target.ClearComments
IsCopyPaste = True
End If

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worksheet_Change Event - Macro kills copy and paste

Rob,

Alan said the same code is the Worksheet_SelectionChange
event, so that will still cause the code to exacute once:
after the selection has changed, but before the Copy
command is initiated. I don't think it will be a problem
with Alan's code that only applies formating, but maybe a
better solution is to trap the filter change?

Any thoughts?

-----Original Message-----
Hi Alan,

The value of Application.CutCopyMode will tell you

whether a user has a
cut or copy operation in progress when your event

procedure fires, something
like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.CutCopyMode = 0 Then
''' User hasn't copied anything,
''' run your macro here.
End If
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Alan" wrote in message
...

Hi All,

I have a macro running upon a Worksheet_Change and

Worksheet_SelectionChange
event from within a worksheet code (not a module).

When a change is made to the worksheet, which is a

filtered list, it calls
a
sub which checks which columns are filtered and

changes the background
colour to make it easier to see, or changes it back to

no fill if the
filter
was removed.

However, if a user tries to copy and paste from one

cell to another, when
they move the cell pointer up a cell (say), one of the

events is triggered
and by the time the macro has run, the contents of the

cell that was
copied
has been lost and paste is ineffective.

I am wondering if there is some way for me to check in

the event procedure
whether the user has tried to copy something, and if

so, then not call the
macro?

Thanks in advance for any help you can render,

Alan.





.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Worksheet_Change Event - Macro kills copy and paste

"Miss Kim" wrote in message
...
Rob,

Alan said the same code is the Worksheet_SelectionChange
event, so that will still cause the code to exacute once:
after the selection has changed, but before the Copy
command is initiated. I don't think it will be a problem
with Alan's code that only applies formating, but maybe a
better solution is to trap the filter change?


Hi Kim,

I just provided the Change event code as an example. The same kind of
check would have to be done in SelectionChange as well. Trapping the filter
change itself could be a good alternative, although it would require some
indirect programming. Because changing the autofilter criteria on a
worksheet doesn't fire any events, you'd have to do something like add a
volatile function to the worksheet, trap the Calculate event, and check for
a change in the filter criteria. This process itself would still need to be
prevented from inadvertently canceling a user's copy operation too, though.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 188
Default Worksheet_Change Event - Macro kills copy and paste

"Rob Bovey" wrote in message
...

Hi Alan,

The value of Application.CutCopyMode will tell you whether a user
has a cut or copy operation in progress when your event procedure
fires, something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.CutCopyMode = 0 Then
''' User hasn't copied anything,
''' run your macro here.
End If
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


Hi Rob,

Your code did the job perfectly.

However - once I made that change, I noticed that the less excel literate
users were filtering the list, and copying down through filtered rows, thus
trashing everything in the 'hidden filtered' rows that are not shown.

I should have anticipated this, but due to the 'bug' that you helped me
resolve, it had not been an issue due to the 'disabling' of the copy / paste
functionality.

Therefore, I have actually removed the code that you supplied, and returned
it back to the original position.

The 'bug' have now been re-designated as a 'feature'!!

Thanks anyway - I learnt something if nothing else.

Regards,

Alan.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling WORKSHEET_CHANGE event Jase Excel Discussion (Misc queries) 1 April 25th 08 04:32 PM
Controling the Worksheet_Change Event? DCSwearingen Excel Discussion (Misc queries) 3 May 25th 06 08:32 PM
Worksheet_Change event question marwan hefnawy Excel Programming 1 September 10th 03 08:53 PM
xl97 and Worksheet_Change event ? Greg Wilson[_3_] Excel Programming 1 September 10th 03 04:17 AM
Worksheet_Change Event Not Working Michael Beckinsale Excel Programming 0 August 1st 03 02:43 PM


All times are GMT +1. The time now is 10:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"