Copy and paste range - source range still selected.

Herakles

Well-known Member
Joined
Jul 5, 2020
Messages
927
Office Version
  1. 365
Platform
  1. Windows
Hi All

Getting stuck on the complicated coding I can accept but overcoming what should be simple problem to solve seems
to take a disproportionate amount of time.

All I am doing is copying and pasting the values from a range in one worksheet to the same sized range in another worksheet.

VBA Code:
Worksheets("Results").Range("A1:A10").Copy Worksheets("Temp").Range("D1:D10")
Application.CutCopyMode = False

The range Worksheets("Results").Range("A1:A10") is still selected after the the code is run.

How does one get around this problem?

I can select another cell, A1 on 'Results' for example, but I can only do that if the 'Results' worksheet is active. Is there a way to do this
without making the 'Results' worksheet active?

I can set a range object to each of the source and target ranges and assign the values of the source range to the target range.

VBA Code:
Dim rngSourceRange  As Range
Dim rngTargetRange  As Range
    
Set rngSourceRange = WsResults.Range("A1:A10")
Set rngTargetRange = Worksheets("Temp").Range("D1").Resize(rngSourceRange.Rows.Count, 1)
    
rngTargetRange = rngSourceRange

But is this a good / acceptable way of doing the same thing? There seems to be few recommendations of this technique online.

Thanks for any help that you can give me.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This line of code
VBA Code:
Worksheets("Results").Range("A1:A10").Copy Worksheets("Temp").Range("D1:D10")
Does not select anything & neither sheet needs to be the activesheet.
So not quite sure what you are saying.
 
Upvote 0
This line of code
VBA Code:
Worksheets("Results").Range("A1:A10").Copy Worksheets("Temp").Range("D1:D10")
Does not select anything & neither sheet needs to be the activesheet.
So not quite sure what you are saying.

Further investigation reveals that the range copied appears to be selected even though it is not but it certainly does
stand out in a different background colour.

When I chnge the active cell in any worksheet, the highlighting disappears.
 
Upvote 0
What is the rest of your code?
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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