?
Solved

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

Posted on 2003-11-12
3
Medium Priority
?
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

719 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