Unable to set the Chart type to XY Plotter

A

Amit Kale

I am trying to set the chart types to XYScatter through code. I am
using the Createobject(Excel.App...) instead of referencing the excel
object.

However, i end up setting the chart type to any of the XY Scatter (XY
Scatt with data points connected, smoothed lines, etc) but cannot
create the simple XYScatter(just points).
The chartType for XYScatter starts from 71 thru 74 (70 is the pie
chart and 75 is area chart).

Has any bdy come across such problem, any suggestions??

Thanks

Heres the code:

Set xlChart = xlChartSheet.chartobjects.Add(360, 5, 350, 250).Chart
With xlChart
.ChartType = 72
.SeriesCollection.Add Source:=xlWS.Range("A4:A" & lastRow & ", " &
xlWS.Cells(4, colCount + 1).Address & ":" & Left(xlWS.Cells(4,
colCount + 1).Address, 3) & lastRow), RowCol:=2

.SeriesCollection(1).XValues = xlWS.Range("P4:p" & lastRow)
.SeriesCollection(1).Values = xlWS.Range("E4:E" & lastRow)

.SeriesCollection(1).TrendLines.Add
.HasTitle = True
.ChartTitle.Caption = "Gas vs Power Price"
.HasLegend = False
.PlotArea.Height = 280
.PlotArea.Width = 490
End With
 
J

Jon Peltier

Amit -

You need to use the correct long value for xlXYScatter, which is -4169.

- Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top