-
Hi Maka,
If you have Office 2000 or greater you can do this using OWC (Microsoft Office Web Compoments) by first creating a spreadsheet on the userform and linking the userform chart to data on that spreadsheet. (Note that if you wish you can set the spreadsheet to Visible = False when the userform's shown).
Go to Tools > Additional Controls > Microsoft Office Chart 9.0 (this sets a reference to Microsoft Office Web Components 9.0). Add a Microsoft Office Spreadsheet 9.0 control to the user form.
NOTE: If the Microsoft Office Spreadsheet 9.0 (or Spreadsheet) control and the Microsoft Office Chart 9.0 (or ChartSpace) controls are not visible in the Control Toolbox, follow these steps...
1) Right-click the Control Toolbox and click Additional Controls.
2) Click both the Microsoft Office Chart 9.0 and Microsoft Office Spreadsheet 9.0 check boxes and then click OK...
This is the userform code example used in the attachment:
[vba]Option Explicit
Private Sub UserForm_Initialize()
'Spreadsheet1.Visible = False
With ChartSpace1
' Add a chart.
.Charts.Add
' Set the data source of the chart to the Spreadsheet control.
.DataSource = Spreadsheet1
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
[/vba]
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules