chart on userform

G2K

Active Member
Joined
May 29, 2009
Messages
355
Hi all,

I am trying to create a chart on userform.but unfortunately the code generates error "Copile Error - can not find Project and Library" when we choose chart type -".Type = chChartTypeBarClustered"

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
.SeriesCollection.Add

' Set the properties of data series.
With .SeriesCollection(0)
.SetData chDimSeriesNames, 0, "B1"
.SetData chDimCategories, 0, "A2:A15"
.SetData chDimValues, 0, "B2:B15"
End With

' Display the legend.
.HasLegend = True
End With
End With

End Sub


Please help.........
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I could be wrong but I don't think that you can add a chart (object or sheet) to a userform. Adding an image control to the userform and then filling it with a picture of the chart does the same thing. This stuff might help? Dave
Code:
Dim Fname As String
Fname = ThisWorkbook.Path & "\" & "Filename.gif"
ActiveChart.Export Filename:=Fname, FilterName:="GIF"
Userform1.Image1.Picture = LoadPicture(Fname)
Kill Fname
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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