Copying a range that changes...

scotthannaford1973

Board Regular
Joined
Sep 27, 2017
Messages
115
Office Version
  1. 2010
Platform
  1. Windows
Hi

I have a table, lets say columns A to D on "Sheet 1" and I want to be able to select the table, copy it and paste it elsewhere. The only proviso is that as the table gets data from a pivot table, the length of the table changes - sometimes it's A1:D50 and the next day it may be A1:D47 or A1:D100 etc

I'd like to just be able to select the table as far as the bottom row where A is populated - so if A1:A50 have content but A51 onwards is blank, I want to be able to select A1:D50

The rest of the copy and paste VB is fine, but I have no idea how to select "only the populated part of the table"...

any help would be much appreciated!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
See if this dynamically selects all the data you want:
VBA Code:
Range("A1").CurrentRegion.Copy
 
Upvote 1
Solution
Thanks - that's spot on - wasn't aware of "range"!
You are welcome.

"Range" is not the key part here, "CurrentRegion" is. "CurrentRegion" is the same if you hit "CTRL+SHIFT+*" on your keyboard.
Basically, from whatever cell you start from Current Region will select the Contiguous Range from that cell.
So it will go down as far as the first entirely blank row, to the right as far as the first entirely blank column, and then the same for up and to the left.
 
Upvote 1

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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