+ Reply to Thread
Results 1 to 3 of 3

Changing trendline color and weight

  1. #1
    Registered User
    Join Date
    03-25-2006
    Posts
    7

    Changing trendline color and weight

    I need to use VBA code to change the color and the thickness of trendlines in a chart I generated using VBA. For the life of me I cannot generate working code to change these trendline properties. Surely this can be done. If someone could help me out it would be greatly appreciated.

  2. #2
    Peter T
    Guest

    Re: Changing trendline color and weight

    Sub test()
    Dim cht As Chart
    Dim sr As Series
    Dim tr As Trendline

    Set cht = ActiveSheet.ChartObjects(1).Chart
    Set sr = cht.SeriesCollection(1)
    Set tr = sr.Trendlines(1)

    tr.Border.ColorIndex = 3
    tr.Border.LineStyle = xlDash 'xlContinuous
    tr.Border.Weight = xlThick ' xlThin

    End Sub

    Regards,
    Peter T

    "biosci" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I need to use VBA code to change the color and the thickness of
    > trendlines in a chart I generated using VBA. For the life of me I
    > cannot generate working code to change these trendline properties.
    > Surely this can be done. If someone could help me out it would be
    > greatly appreciated.
    >
    >
    > --
    > biosci
    > ------------------------------------------------------------------------
    > biosci's Profile:

    http://www.excelforum.com/member.php...o&userid=32827
    > View this thread: http://www.excelforum.com/showthread...hreadid=526311
    >




  3. #3
    Greg Wilson
    Guest

    RE: Changing trendline color and weight

    Formating the trendline's border is what you're looking for I believe:

    Sub Test()
    Dim cht As Chart
    Set cht = ActiveSheet.ChartObjects(1).Chart
    With cht.SeriesCollection(1).Trendlines(1).Border
    .ColorIndex = 3
    .Weight = xlThin
    .LineStyle = xlContinuous
    End With
    End Sub

    Regards,
    Greg

    "biosci" wrote:

    >
    > I need to use VBA code to change the color and the thickness of
    > trendlines in a chart I generated using VBA. For the life of me I
    > cannot generate working code to change these trendline properties.
    > Surely this can be done. If someone could help me out it would be
    > greatly appreciated.
    >
    >
    > --
    > biosci
    > ------------------------------------------------------------------------
    > biosci's Profile: http://www.excelforum.com/member.php...o&userid=32827
    > View this thread: http://www.excelforum.com/showthread...hreadid=526311
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1