vba to assemble cell address

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
174
I would like a range that includes the number of rows +1 a cell value states. I've tried various versions of the code below.

'Range("C2", Range("C" & Range("MonitorTotal")+1).Value).Copy

As you can see I want the range from C2 to C and the value from the named cell "MonitorTotal" +1.

Thanks for any help

Tom
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You were close:

Code:
Range("C2", Range("C" & Range("MonitorTotal").Value +1)).Copy

or just:

Code:
Range("C2").Resize(Range("MonitorTotal").Value).Copy
 
Upvote 0
I kept trying and finally stumbled into the code

Range("C2", "C" & 1 + Range("MonitorTotal").Value).Copy

Tom
 
Upvote 0
Thanks Rory.
Works perfectly. Even better would be a more direct way to copy the range. Is there a way to use Offset rather than adding to "MonitorTotal"?
Something like

Range("C2" , Offset(Range("MonitorTotal").Value), 0).Copy

In essence, using the cell value in "MonitorTotal" as the row offset property.

Thanks
Tom
 
Upvote 0
If your named range has the value 3, which range do you want to copy: C2:C4 or C2:C5? If it's the former, you could use the Resize version I posted.
 
Upvote 0
Thanks Rory

That operation will be repeated many times in my macro. From many locations. Keeping track of how many rows from the top of the sheet would have been a pain.

Tom
 
Upvote 0
Tom

You did not answer Rory's question in message 7. After all, should it be C2:C4 or C2:C5?

M.
 
Upvote 0

Forum statistics

Threads
1,216,049
Messages
6,128,496
Members
449,455
Latest member
jesski

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