Solved

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

Posted on 2003-11-12
3
368 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Saving history changes to sub form 4 48
Recommendation vb6 to vb.net or others 14 175
Automatic Email Reminder 4 57
VBA - If Bookmark = "XXBOOKMARKXX" then 15 40
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 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