Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Edit:</p> <p>OK, this seems to handle more cases better. The triggering code is the same, but here is new code for the module:</p> <pre><code>Function SeriesRange(s As Series) As Range Dim sf As String, fa() As String sf = s.Formula sf = Replace(sf, "=SERIES(", "") If sf = "" Then Set SeriesRange = Nothing Exit Function End If fa = Split(sf, ",") Set SeriesRange = Range(fa(2)) End Function Sub x(c As Chart) Dim sc As Series Dim sr As Range If SeriesRange(c.SeriesCollection(1)) Is Nothing Then Exit Sub End If Set sr = SeriesRange(c.SeriesCollection(1)) sr.CurrentRegion.Interior.ColorIndex = xlNone For Each sc In c.SeriesCollection If sc.Interior.Color &gt; 1 Then SeriesRange(sc).Interior.Color = sc.Interior.Color ElseIf sc.Border.ColorIndex &gt; 1 Then SeriesRange(sc).Interior.Color = sc.Border.Color ElseIf sc.MarkerBackgroundColorIndex &gt; 1 And sc.MarkerBackgroundColorIndex &lt; 57 Then SeriesRange(sc).Interior.ColorIndex = sc.MarkerBackgroundColorIndex ElseIf sc.MarkerForegroundColorIndex &gt; 1 And sc.MarkerForegroundColorIndex &lt; 57 Then SeriesRange(sc).Interior.ColorIndex = sc.MarkerForegroundColorIndex Else MsgBox "Unable to determine chart color for data series " &amp; sc.Name &amp; " ." &amp; vbCrLf _ &amp; "It may help to assign a color rather than allowing AutoColor to assign one." End If Next sc End Sub </code></pre> <p>/Edit</p> <p>This is probably more barbaric than elegant, but I think it does what you want. It involves your first bullet point to get the range from the <code>Series</code> object, along with a sub to run through all the <code>Series</code> objects in the <code>SeriesCollection</code> for the chart. This is activated on <code>Chart_DeActivate</code>. Most of this code is jacked - see comments for sources.</p> <p>In a module:</p> <pre><code>Function SeriesRange(s As Series) As Range Dim sf As String, fa() As String Dim i As Integer Dim result As Range sf = s.Formula sf = Replace(sf, "=SERIES(", "") fa = Split(sf, ",") Set SeriesRange = Range(fa(2)) End Function Sub x(c As Chart) Dim sc As Series Dim sr As Range Set sr = SeriesRange(c.SeriesCollection(1)) sr.CurrentRegion.Interior.ColorIndex = xlNone For Each sc In c.SeriesCollection SeriesRange(sc).Interior.Color = sc.Interior.Color Next sc End Sub </code></pre> <p>In the <code>ThisWorkbook</code> object module:</p> <pre><code>' Jacked from C Pearson http://www.cpearson.com/excel/Events.aspx ' Public WithEvents CHT As Chart Private Sub CHT_Deactivate() x CHT End Sub Private Sub Workbook_Open() Set CHT = Worksheets(1).ChartObjects(1).Chart End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload