+ Reply to Thread
Results 1 to 4 of 4

Apply macro to all but two series in charts

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    Christchurch, NZ
    MS-Off Ver
    Excel 2010
    Posts
    6

    Apply macro to all but two series in charts

    Hi all,

    I am using the following code to automatically update the colour of my chart's lines to the same colour as the cells. However there are 33 series in each of my charts and I only want the code to apply to series 1 - 31 and not series 32/33.

    Dim MySeries As Series
    Dim FormulaSplit As Variant
    Dim SourceRange As Range
    Dim SourceRangeColor As Long

    'Loop through all charts in the active sheet
    For Each oChart In ActiveSheet.ChartObjects

    'Loop through all series in the target chart
    For Each MySeries In oChart.Chart.SeriesCollection

    'Get Source Data Range for the target series
    FormulaSplit = Split(MySeries.Formula, ",")

    'Capture the first cell in the source range then trap the color
    Set SourceRange = Range(FormulaSplit(2)).Item(1)
    SourceRangeColor = SourceRange.DisplayFormat.Interior.Color

    On Error Resume Next

    'Coloring for Excel 2007 and 2010
    MySeries.MarkerBackgroundColor = SourceRangeColor
    MySeries.MarkerForegroundColor = SourceRangeColor
    MySeries.Format.Line.ForeColor.RGB = SourceRangeColor
    MySeries.Format.Line.BackColor.RGB = SourceRangeColor
    MySeries.Format.Fill.ForeColor.RGB = SourceRangeColor
    MySeries.Format.Line.Weight = 1.5
    MySeries.Format.Line.DashStyle = 4
    MySeries.Format.Line.Style = msoLineSingle
    MySeries.MarkerStyle = xlMarkerStyleNone

    Next MySeries
    Next oChart

    End Sub

    Any help would be greatly appreciated.

    Cheers,

    Ben
    Last edited by benjthom; 12-02-2013 at 10:07 PM.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Apply macro to all but two series in charts

    Hi benjthom,

    Post back re how this goes:

    Please Login or Register  to view this content.
    If could also wrap your code in the appropriate tags as I have done, it would be appreciated.

    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    05-08-2013
    Location
    Christchurch, NZ
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Apply macro to all but two series in charts

    Hi Robert,

    I tried using your code but it still applied the macro to all of the series in my charts. An alternative solution I found on /r/excel is provided below. Thanks for your help anyway.

    Please Login or Register  to view this content.
    Regards,

    Ben

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Apply macro to all but two series in charts

    See if changing the Or part of this statement...

    Please Login or Register  to view this content.
    ...to And makes a difference.

    Robert

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Apply format of a series to a similar series in a different chart
    By Skiffie in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-05-2013, 10:43 PM
  2. =SERIES and charts (adding two cells in a series formula)
    By benmmaddog in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-11-2013, 09:52 PM
  3. Macro needed for multiple series of data to plot unique charts
    By ehelliar in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 04-23-2011, 11:50 AM
  4. How to apply conditions on charts
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-12-2009, 09:57 AM
  5. Replies: 1
    Last Post: 05-21-2006, 11:15 AM

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