Expanding Range for charts

Mielie

New Member
Joined
Feb 1, 2005
Messages
1
Hi,

I am aware that there are other (better) ways of referencing dynamic chart source data. However, if anyone can tell me why this code I've put together doesn't work, it would be much appreciated.
The first bit of code defines the data range, and this appears to work fine. I like this way of selecting data, as there often rows of 'noise' between the rows those I want to chart, and the data may expand into an unknown number of columns. The rows to be charted will always have the same number of columns so this is not an issue.

It seems that the defined ranges are not accepted once I try and set the source data of the chart.

Code:
Sub MakeChart()
    Dim range1 As Range
    Dim range2 As Range
    Dim range3 As Range

    Worksheets("Sheet1").Activate
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Set range1 = ActiveCell.CurrentRegion
        
    Range("A4").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Set range2 = ActiveCell.CurrentRegion
    
    Range("A7").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Set range3 = ActiveCell.CurrentRegion

    Charts.Add
    ActiveChart.ApplyCustomType ChartType:=xlUserDefined,_
TypeName:= "Rainfall"
  
    ActiveChart.SetSourceData Source:=Sheets("Sheet1")._
Range(range1, range2, range3), PlotBy:=xlRows

Any comments would be most welcome.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,790
Messages
6,121,608
Members
449,038
Latest member
apwr

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