Copy data w/o selecting a range

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
539
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I was wondering if these commands could be rewritten to a single line and avoid having to select the range before copying the data. I need everything in the sheet from the second row on starting with the first column. I've tried a few variations but having found anything that works.

Code:
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Generaly speaking, to remove Select statements from code...

find anything that says Selection, and replace that with whatever was previously selected.

So

Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy

becomes

Range(Range("A2"), ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy

becomes

Range(Range("A2"), ActiveCell.SpecialCells(xlLastCell)).Copy


You can (and should) also replace ActiveCell with whatever cell was selected

so it becomes

Range(Range("A2"), Range("A2").SpecialCells(xlLastCell)).Copy


Hope that helps.
 
Last edited:
Upvote 0
Thanks for the tips guys. I saved this in my reference file for future use. I should have remembered "rows.count" as you helped me out with that code in the past VOG. I did manage to get it working like so:
Code:
Sheets("Data").Range("A2", ActiveCell.SpecialCells(xlLastCell)).Copy
I was trying to clean up some code and remove select statements and also eliminate having to switch back and forth between sheets.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,894
Members
452,948
Latest member
Dupuhini

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