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.
Any comments would be most welcome.
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.