JamesW
Well-known Member
- Joined
- Oct 30, 2009
- Messages
- 1,197
Hi guys,
I'm trying to add a chart to a userform using the Microsoft Office Chart 9.0 control.
I have the following code, taken from a website, but I get a 'type mismatch' error at the red line:
How on earth do I set the data series to a range on a spreadsheet?
Cheers,
James
I'm trying to add a chart to a userform using the Microsoft Office Chart 9.0 control.
I have the following code, taken from a website, but I get a 'type mismatch' error at the red line:
Code:
Option Explicit
Private Sub UserForm_Initialize()
'Sheet1.Visible = False
With ChartSpace1
' Add a chart.
.Charts.Add
' Set the data source of the chart to the Spreadsheet control.
[COLOR=red][B]Set ChartSpace1.DataSource = Sheets("Sheet1").Range("H2:S3")
[/B][/COLOR]
With .Charts(0)
' Create a bar chart.
.Type = chChartTypeBarClustered
' Add two data series to the chart.
.SeriesCollection.Add
.SeriesCollection.Add
' Set the properties of the first data series.
With .SeriesCollection(0)
.SetData chDimSeriesNames, 0, "B1"
.SetData chDimCategories, 0, "A2:A5"
.SetData chDimValues, 0, "B2:B5"
End With
' Set the properties of the second data series.
With .SeriesCollection(1)
.SetData chDimSeriesNames, 0, "C1"
.SetData chDimValues, 0, "C2:C5"
End With
' Display the legend.
.HasLegend = True
End With
End With
End Sub
How on earth do I set the data series to a range on a spreadsheet?
Cheers,
James