ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   deselecting a highlighted range after a VBA copy procedure (https://www.excelbanter.com/excel-programming/284935-deselecting-highlighted-range-after-vba-copy-procedure.html)

Paul James[_3_]

deselecting a highlighted range after a VBA copy procedure
 
I've noticed that when I run a copy and paste operation in VBA using
statements of the form

Worksheet1.Range1.Copy
Worksheet2.Range2.pastespecial

that target range, Range2, remains selected unless I perform some other
operation on a range in Worksheet2.

I would like to unselect that range after the paste method is executed, but
I'd rather not use a Select method at that point in my code, because I don't
want to make Worksheet2 the active sheet. Is there a way to deselect that
highlighted range without using a Select statement?

Thanks in advance.

Paul



ExcelBanter AI

Answer: deselecting a highlighted range after a VBA copy procedure
 
Hi Paul,

Yes, there is a way to deselect the highlighted range without using a Select statement. You can use the Application.CutCopyMode property to clear the copy buffer, which will automatically deselect the range.

Here's an example of how you can modify your code to include this:
  1. Formula:

    Worksheet1.Range1.Copy 

  2. Formula:

    Worksheet2.Range2.PasteSpecial 

  3. Formula:

    Application.CutCopyMode False 


This will clear the copy buffer and deselect the range in Worksheet2 without making it the active sheet.

Vasant Nanavati

deselecting a highlighted range after a VBA copy procedure
 
I don't believe there is a way without switching to the second sheet and
switching back.

--

Vasant


"Paul James" wrote in message
...
I've noticed that when I run a copy and paste operation in VBA using
statements of the form

Worksheet1.Range1.Copy
Worksheet2.Range2.pastespecial

that target range, Range2, remains selected unless I perform some other
operation on a range in Worksheet2.

I would like to unselect that range after the paste method is executed,

but
I'd rather not use a Select method at that point in my code, because I

don't
want to make Worksheet2 the active sheet. Is there a way to deselect that
highlighted range without using a Select statement?

Thanks in advance.

Paul





Alex J

deselecting a highlighted range after a VBA copy procedure
 
Paul,
If you are transferring values, I think this will work without selecting
the range:

Worksheet2.Range2.Value = Worksheet1.Range1.Value

I also know that:
Worksheet1.Range1.Copy Worksheet2.Range2

will work, but this is not PasteSpecial, of course.

Alex J

"Paul James" wrote in message
...
I've noticed that when I run a copy and paste operation in VBA using
statements of the form

Worksheet1.Range1.Copy
Worksheet2.Range2.pastespecial

that target range, Range2, remains selected unless I perform some other
operation on a range in Worksheet2.

I would like to unselect that range after the paste method is executed,

but
I'd rather not use a Select method at that point in my code, because I

don't
want to make Worksheet2 the active sheet. Is there a way to deselect that
highlighted range without using a Select statement?

Thanks in advance.

Paul





TBA[_2_]

deselecting a highlighted range after a VBA copy procedure
 
Paul,

This worked for me from recording a Macro such as you described then
checking the code:

Application.CutCopyMode = False

-gk-


"Paul James" wrote in message
...
I've noticed that when I run a copy and paste operation in VBA using
statements of the form

Worksheet1.Range1.Copy
Worksheet2.Range2.pastespecial

that target range, Range2, remains selected unless I perform some other
operation on a range in Worksheet2.

I would like to unselect that range after the paste method is executed,

but
I'd rather not use a Select method at that point in my code, because I

don't
want to make Worksheet2 the active sheet. Is there a way to deselect that
highlighted range without using a Select statement?

Thanks in advance.

Paul





Paul James[_3_]

deselecting a highlighted range after a VBA copy procedure
 
That will work for me. Good idea.

Thanks, Alex.

Paul



Paul James[_3_]

deselecting a highlighted range after a VBA copy procedure
 
Thanks for the response, gk.

Unfortunately, while Application.cutcopymode = false turns off the
highlighted marquee from the range that was copied from, but it doesn't
deselect the range that was copied to.

See Alex's suggestion elsewhere in this thread for a way to get the desired
effect.

Paul




All times are GMT +1. The time now is 05:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com