|
-
Aug 8th, 2011, 11:18 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Copy Paste Selection Change Macro Clearing Clipboard
Ever since I started messing with VBA, this problem has Plagued me. There has to be a way to deal with it.
I do a lot of Copy and Pasting around the Sheets/Workbook, and I made a code that Error Checks my editing. I would like this error check code to work with the Selection Change Code Type (I don't know what that is called). But, it erases the cipboard when I select the cell I want to paste to.
Is there a way to say If Ctrl-C / Copy Mode is active, then exit subject?
-
Aug 9th, 2011, 05:03 AM
#2
Re: Copy Paste Selection Change Macro Clearing Clipboard
you can try
vb Code:
if application.cutcopymode = true then exit sub
but i do not know if that is actually what you want
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 9th, 2011, 07:59 AM
#3
Re: Copy Paste Selection Change Macro Clearing Clipboard
Here's an idea: Why don't you just fill the data using the other cell's value instead of copy - paste. That consumes less resources, runs faster and will not trigger your event.
Instead of:
Code:
Range("B10").Select
Selection.Copy
Range("D10").Select
ActiveSheet.Paste
Use this:
Code:
Range("D10").Formula = Range("B10").Formula
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Aug 9th, 2011, 10:45 AM
#4
Thread Starter
Hyperactive Member
Re: Copy Paste Selection Change Macro Clearing Clipboard
I couldn't get this to work. When I put an End If at the end of the Macro, it kept saying End If without Block If. Does Then Exit Sub not require an End If? It doesn't work, the macro still runs.
Code:
if application.cutcopymode = true then exit sub
This works;
Code:
if application.cutcopymode=false then
do macro
I've thought about doing this, but sometimes the info is not the same.
Code:
Range("D10").Formula = Range("B10").Formula
The goal is to circumvent the Selection Change Macro from exiting CutCopyMode and wiping the Clipboard.
So why wouldn't this statement work?
Code:
if application.cutcopymode = true then exit sub
Can you think of any other ways?
Can put a code in the beginning that backs up the clipboard somehow? I mean you can programatically copy paste, so why does any other macro clear the Clipboard?
-
Aug 9th, 2011, 11:48 AM
#5
Re: Copy Paste Selection Change Macro Clearing Clipboard
Show us where are you cutting and where are you pasting. I do not think of a case where you can't do it with assignments instead of using the clipboard. The same way you select the source cells and destination cells you can select them for the assignment.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Aug 9th, 2011, 05:16 PM
#6
Thread Starter
Hyperactive Member
Re: Copy Paste Selection Change Macro Clearing Clipboard
I do not think of a case where you can't do it with assignments instead of using the clipboard
Are you talking about hard coding like this?
Code:
Range("D10").Formula = Range("B10").Formula
I could do that, but I like to copy and past things all over the place. Think Picasso with the Copy paste haha! I need my helper (Error Check) macro to not wipe the clipboard.
This works, but you have to double click a cell to get out of copy paste, and then click somewhere to get the Macro to run. I mean that's ok, but that's a lot of clicking for a lazy person.
Code:
if application.cutcopymode=false then
do macro
Anybody know why when a Macro Runs it clears the Clipboard? Maybe that should be an option.
-
Aug 9th, 2011, 05:22 PM
#7
Re: Copy Paste Selection Change Macro Clearing Clipboard
again, either way its easier to do an assignment in code than a copy paste. But you fail to provide the code where you are doing your copy-paste so I can tell you where you can change all that and save on resources, code, risk and that issue that is bugging you.
If you are doing code it is seldom better to do a copy-paste combination and only in very special sircumnstances.
Please show me your bit of code where you do the copy and paste.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Aug 9th, 2011, 09:25 PM
#8
Thread Starter
Hyperactive Member
Re: Copy Paste Selection Change Macro Clearing Clipboard
No no, I'm Copy and Pasting (ctrl-C, ctrl-V) the macro I want to run in the Selection Change is just doing some checks on my work. Problem is, when I do ctrl-C, and then select a cell, the Selection Change code fires, and wipes the Clipboard or it's exiting Cut Copy Mode. Not sure which it's doing.
Understand?
-
Aug 10th, 2011, 05:15 AM
#9
Re: Copy Paste Selection Change Macro Clearing Clipboard
I couldn't get this to work. When I put an End If at the end of the Macro, it kept saying End If without Block If. Does Then Exit Sub not require an End If? It doesn't work, the macro still runs.
you do not need an end if if the whole condition is on a single line
vb Code:
if application.cutcopymode = true then exit sub
is the same as
vb Code:
if application.cutcopymode then exit sub end if
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 11th, 2011, 01:58 PM
#10
Thread Starter
Hyperactive Member
Re: Copy Paste Selection Change Macro Clearing Clipboard
These 2 methods appear to exit sub when I step through the code with a cell in copy mode. However, when I actually copy the cell and 'click the cell to paste in', it deactivates copy paste mode. Ideas why that is?
Code:
If Application.CutCopyMode Then Exit Sub
Code:
If Application.CutCopyMode = 1 Then Exit Sub
Nevermind, was messing with the wrong sheet. It works
Last edited by tome10; Aug 11th, 2011 at 02:08 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|