+ Reply to Thread
Results 1 to 3 of 3

Macro that changes line styles based on the series' name

  1. #1
    Registered User
    Join Date
    05-10-2006
    Posts
    5

    Question Macro that changes line styles based on the series' name

    Hi,

    I have a question regarding changing the line styles in a graph with a macro.

    There are several series in the graph, however, they are named either "SOT_*" or "EOT_*" . * being the rest of the series name.

    Currently, all of the lines are solid. But I wish to change all the series with the prefix EOT to dashed and leave the others as they are.

    How do I create a macro loop code that looks for the prefix of the series' name and change the line style based on the prefix?

    Thanks a bunch!

  2. #2
    Tony James
    Guest

    Re: Macro that changes line styles based on the series' name

    trumptmast wrote:

    > Hi,
    >
    > I have a question regarding changing the line styles in a graph with a
    > macro.
    >
    > There are several series in the graph, however, they are named either
    > "SOT_*" or "EOT_*" . * being the rest of the series name.
    >
    > Currently, all of the lines are solid. But I wish to change all the
    > series with the prefix EOT to dashed and leave the others as they are.
    >
    > How do I create a macro loop code that looks for the prefix of the
    > series' name and change the line style based on the prefix?
    >
    > Thanks a bunch!
    >
    >
    > --
    > trumptmast


    When doing something like this I use the macro recorder to see what
    objects Excel uses. So with a chart on sheet1 I started the recorder
    and double-clicked one of the series lines in question and continued
    with the Format Data Series dialog.

    It turns out that it uses the SeriesCollection Collection Object, so
    with that information it was quite easy to code this macro:

    Sub FormatDataSeries()
    Dim myChart As SeriesCollection
    Dim mySeries As Series

    Set myChart = Worksheets(1).ChartObjects(1).Chart.SeriesCollection

    For Each mySeries In myChart
    Debug.Print mySeries.Name
    If Left(mySeries.Name, 4) = "EOT_" Then
    mySeries.Border.LineStyle = xlDash
    End If
    Next
    End Sub

    hth, Tony


  3. #3
    Registered User
    Join Date
    05-10-2006
    Posts
    5

    Talking

    Works quite well. Thanks a lot!

+ 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