using a cell reference in a range command in VBA

Bickerton

New Member
Joined
Nov 12, 2019
Messages
4
Hi everyone,

I am new on here and have a small problem. I want a command button to copy a range of cells and past somewhere else on the sheet. Simple enough I know, but if I have range("A1:A10") no problem, but I want range(A1:A&H1). I know this won't work, but I want the value to change to whatever i type in H1 to change the length of the range of cells. Hope that makes sense.
Thanks
Gavin
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi & welcome to MrExcel.
How about
Code:
Range ("A1:A" & Range("H1").Value)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Sorry Fluff (or anyone else!), I have another question! I want to referance a cell in both parts of the range, but it keeps returning an error now using this code: [FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] Range("C" & Range("H2").Value):C" & Range("j32").Value).Select Is this possible or will I have to find another workaround? I also want to add 1 to the value in H2, not sure if this is possible or just do it in another cell on the spreadsheet?[/FONT]
 
Upvote 0
Try
Code:
Range("C" & Range("H2").Value + 1 & ":C" & Range("j32").Value).Select
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,735
Messages
6,180,636
Members
452,992
Latest member
TokugawaIesuma

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