Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,075
- Office Version
- 2019
- Platform
- Windows
I have this code that generates a graph. I would like to display the graph in a userform. I'm getting an error and I'm not sure why. Please help.
Thanks
Thanks
Code:
Sub MyCandlestick()Dim OHLCChart As ChartObject
Dim LRow As Long
Dim ChartName As String, fname As String
LRow = Range("AA" & Rows.Count).End(xlUp).Row
Set OHLCChart = ActiveSheet.ChartObjects.Add(Left:=Range("A15").Left, Width:=400, Top:=Range("A15").Top, Height:=250)
With OHLCChart.Chart
.SetSourceData Source:=ActiveSheet.Range("AA1:AE" & LRow) ' & nRows)
.ChartType = xlStockOHLC
.HasTitle = True
.ChartTitle.Text = cbName
.Axes(xlValue, xlPrimary).HasTitle = False
.HasLegend = False
.PlotArea.Format.Fill.ForeColor.RGB = RGB(220, 230, 241)
With .ChartGroups(1)
.UpBars.Format.Fill.ForeColor.RGB = RGB(0, 176, 80)
.DownBars.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With
.ChartArea.Format.Line.Visible = msoFalse
.Parent.Name = "OHLC Chart"
.Axes(xlCategory).CategoryType = xlCategoryScale
End With
fname = Application.DefaultFilePath & Application.PathSeparator & "TempChart.gif"
OHLCChart.Export Filename:=fname, FilterName:="GIF"
frmData.Image.Picture = LoadPicture(fname)
ActiveSheet.ChartObjects(1).Delete
Kill fname
End Sub