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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
79,695
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
Code:
Range ("A1:A" & Range("H1").Value)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
79,695
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Bickerton

New Member
Joined
Nov 12, 2019
Messages
4
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]
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
79,695
Office Version
  1. 365
Platform
  1. Windows
Try
Code:
Range("C" & Range("H2").Value + 1 & ":C" & Range("j32").Value).Select
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
79,695
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 

Forum statistics

Threads
1,181,439
Messages
5,929,928
Members
436,706
Latest member
Noddyparp

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
Top