Solved

How to set the color of the lines in a (line) excel chart, programmed via visual basic

Posted on 2003-11-12
3
367 Views
Last Modified: 2013-12-26
Hello,

I've already got the following code, I would like to know how I can set the colours of the 3 different seriescollections (ranges) in the chart.
Thnx in advantage.

  Dim objXLRange As Excel.Range
  Dim objXlChart As Excel.Chart
 
  Set objXLRange = excWS.Range("B35", "E37")
  Set objXlChart = excWS.ChartObjects.Add(50, 40, 300, 200).Chart
 
  With objXlChart
    .ChartType = xlLine
    .SetSourceData objXLRange, xlRows
    .HasTitle = True
    With .ChartTitle
      .Characters.Text = "prestaties t.o.v. gemiddelde"
      .Font.Size = 16
      .Font.Name = "Verdana"
    End With
    With .SeriesCollection(1)
      .ApplyDataLabels Type:=xlDataLabelsShowValue
    End With
    With .SeriesCollection(2)
      .ApplyDataLabels Type:=xlDataLabelsShowValue
    End With
    With .SeriesCollection(3)
      .ApplyDataLabels Type:=xlDataLabelsShowValue
    End With
  End With

Greetz,
Peter
0
Comment
Question by:peterhav
3 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 9731927

    Rows("3:3").Select
    With Selection.Interior
        .ColorIndex = 3
        .Pattern = xlSolid
    End With
0
 

Author Comment

by:peterhav
ID: 9732116
I would like to change the colour of the lines in the graph, not of the original rows in the excel sheet.
0
 
LVL 9

Accepted Solution

by:
p_sie earned 100 total points
ID: 9733339
.SeriesCollection(2).Border.ColorIndex = 50            makes the line green!

You can get this code by recording a macro in Excel and then see the code in VBA, like you
can find out may other methodes to do things programmatically in Excel!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question