Vba dynamically add series to chart in Excel

For example, I already have a chart ("Chart1") of Sales data for Q1-2016. When Q2 Sales data becomes available how do I add it to an existing chart using VBA?

excel vba dynamically add series to chart

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub AddChartSeries()
  3. With ActiveSheet.ChartObjects("Chart1").Chart.SeriesCollection.NewSeries
  4. .XValues = ActiveSheet.Range("BU5:BU9")
  5. .Values = ActiveSheet.Range("BW5:BW9")
  6. .Name = ActiveSheet.Range("BW4")
  7. End With
  8. End Sub

Description:

a) Line 3 - Adds a new series with range specified in "Line 4 for X-Axis Labels", "Line 5 for Y-Axis Values" and "Line 6 for Series Name".

Result after Macro execution:

excel vba dynamically add series to chart

 

You can find similar Excel Questions and Answer hereunder

1) How can I find the number of working days between 2 dates using VBA?

2) How do I copy a Table from one location to another and retain all formulas, formats and columnwidths?

3) How can I change the Marker size and Marker line color for all the series in a chart?

4) How can I add and link a Chart Title to a cell value?

5) How can I export a WorkSheet as a PDF using VBA?

6) How can I set FreezePanes in a certain range using VBA?

7) How can I list all files in a folder using VBA?

8) How can I add a background image to a worksheet?

9) How can I shade alternate rows in color using VBA to make it easier to read voluminous data running into hundreds of rows?

10) How do I enter a formula in a cell using VBA (using Absolute Reference)?

 

Here the previous and next chapter