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

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,345
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
 

Forum statistics

Threads
1,081,513
Messages
5,359,227
Members
400,523
Latest member
ExcelNewbie98

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top