VBA code to select two variable ranges in a row

martinrrrr

New Member
Joined
Oct 14, 2015
Messages
6
I recorded a macro to make a chart. I have two ranges that will be used to define the chart Category Axis and the Series Values. The macro recorded the range as:
Range("A1:AF1,A12:AF13").Select
This range will vary depending on the number of columns containing data. The beginning of the range will always be A1 and it will be just row 1 for the first range and the second data range will begin at A12 and end on row 13. What code do I use that will automatically select the variable ranges (at the same time) that will be used to create the chart?

Thanks for any help
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
This range will vary depending on the number of columns containing data.

Can we use row 1 to determine the last column with data?
VBA Code:
n = Cells(1, Columns.Count).End(xlToLeft).Column
Union(Range("A1").Resize(, n), Range("A12:A13").Resize(, n)).Select
 
Upvote 0
Solution
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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