Results 1 to 2 of 2

Thread: Creating a line chart in Excel VBA

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    27

    Creating a line chart in Excel VBA

    Hi everyone,
    I've asked about this before, and decided a pie chart wasnt the way to go. I need a chart to be dyamically created when the Command Button "Display Graph" is pressed, to show the values in the range of cells K12-N50 in the Pipeline sheet (not the totals, just the values themselve). Also, the legend should display the titles in cells K11-N11 in Pipeline.
    For a while it was ok, then started doing something odd. Now its not displaying anything. Also I'd like something inside the code that if the chart that is created dynamically already exists, replace it with the updated graph (delete+replace?).
    If anyone can help, heres the files! (the spreadsheet takes its values from the database)
    Attached Files Attached Files

  2. #2
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: Creating a line chart in Excel VBA

    Hi,

    when you are adding your series, you can only add a single column or row.

    you are trying to add a range of cells:

    VB Code:
    1. Dim TheSeries As Series
    2. Newchart.SeriesCollection.Add _
    3. Source:=Worksheets("Pipeline").Range("K$12:N$50")

    you will need to add more than 1 series to your chart. e.g.
    VB Code:
    1. Newchart.SeriesCollection.Add _
    2. Source:=Worksheets("Pipeline").Range("K$12:K$50")
    3. Newchart.SeriesCollection.Add _
    4. Source:=Worksheets("Pipeline").Range("L$12:L$50")
    5. Newchart.SeriesCollection.Add _
    6. Source:=Worksheets("Pipeline").Range("M$12:M$50")
    7. Newchart.SeriesCollection.Add _
    8. Source:=Worksheets("Pipeline").Range("N$12:N$50")

    also, you are setting your x axis labels incorrectly. should be:
    VB Code:
    1. With NewChart.SeriesCollection(1) 'thsi index should ideally be an incremental count
    2. .XValues = _
    3.     Worksheets("Pipeline").Range("B$12") 'this is the x axis labels

    ideally you should be using variables for a count, and start cells, incrementing them within a loop to cover all series.

    hope this gives you a starting point.
    Last edited by Br1an_g; May 22nd, 2005 at 06:49 AM.
    if you fail to plan, you plan to fail

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width