Need to Specify chart data

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

Hello,

I have VBA code that creats data and places it into a
worksheet. Now, I need to plot it into an existing line
graph in a Chart. Using "help" I located code that shows
how to extend an existing range, and how to add a new
line, but have not found anything that shows how to
replace an existing line. It seems to me it will require
two steps: first to point the chart to the worksheet range
with the data, and then to point the chart to the
worksheet range containing the X axis labels.

Below are the code examples I found for extend and add.
Can you suggest code described above?

Code for Extend...
Charts("Chart4").SeriesCollection.Extend _
Source:=Worksheets("Sheet1").Range("B2:B203")

Code for add...
Charts(1).SeriesCollection.Add _
Source:=Worksheets("sheet1").Range("B2:B203")


thanks

Keith
 
Easiest way to get the code is to run on the macro recorder and manually
edit the ranges specified for the series.
 
Hi Tom,
Good idea. Thanks
keith
-----Original Message-----
Easiest way to get the code is to run on the macro recorder and manually
edit the ranges specified for the series.

--
Regards,
Tom Ogilvy




.
 
I am doing a similar process.

My data resides in a worksheet and I create a seperate chart sheet. See
below.

Dim cChart As Chart
Dim sSeries As Series

Set cChart = Charts.Add(after:=Sheets(Sheets.Count))
cChart.ChartType = xlXYScatterLinesNoMarkers
cChart.PlotBy = xlColumns

' Make sure a series exists
If cChart.SeriesCollection.Count < 1 Then
cChart.SeriesCollection.newSeries

' Set the first series (Repeat the following for each addition series
Set sSeries = cChart.SeriesCollection(1)
With sSeries
.XValues = wsWorksheet.Range("A4:A20")
.Values = wsWorksheet.Range("B4:B20")
.Name = "My New Series
End With

' Make the chart pretty
With cChart
.Name = "MyNewChart"
.HasTitle = True
.ChartTitle.Text = "My Chart Title"
.ChartTitle.Font.Size = 12
.HasLegend = True
' X Axis
With cChart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "X-Axis"
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
' Y Axis
With cChart.Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = "Y-Axis"
.TickLabels.NumberFormat = "0.00"
.Crosses = xlCustom
.CrossesAt = -xlMinimum
End With
End With

I would like to say thanks to Jon Peltier for helping me get the "kinks"
out of this process.
 

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

Back
Top