VBA to select range

betgem

New Member
Joined
Apr 21, 2009
Messages
15
Hello, everyone !

I need a macro that will select and copy a range within a worksheet. Now the range always starts in cell A22 and ends in column J, but in a different row, so could be A22:J40, A22:J67 etc. In a separate cell I have a formula that returns a value that I want to use as the cell reference for my second part of the range (if the cell value is 40, then my range will be A22:J40, if my cell value is 67, then my range should be A22:J67 etc.)
Or to paraphrase the question - how to select a range of cells using cell values as references for the range.

I hope this makes sense and thank you all for your time.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this...

In the below code A1 cell will determine the end cell of column-J

Code:
Sub SelectDataBasedOnEndRangeMentionedInCell()
    Range("A22:J" & Range("A1").Value).Select
End Sub
 
Upvote 0
Thank you both Andrew and Sixthsense, this worked well and was exactly what I needed. Thank you for your time.
 
Upvote 0

Forum statistics

Threads
1,202,975
Messages
6,052,868
Members
444,606
Latest member
rwmhr

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