I have the following code
Sub PieMarkers()
Dim chtMarker As Chart
Dim chtMain As Chart
Dim intPoint As Integer
Dim rngRow As Range
Dim lngPointIndex As Long
Dim thmColor As Long
Dim myTheme As String
Application.ScreenUpdating = False
Set chtMarker = ActiveSheet.ChartObjects("chtMarker").Chart
Set chtMain = ActiveSheet.ChartObjects("chtMain").Chart
Set chtMain = ActiveSheet.ChartObjects("chtMain").Chart
Set rngRow = Range(ThisWorkbook.Names("PieChartValues").RefersTo)
For Each rngRow In Range("PieChartValues").Rows
chtMarker.SeriesCollection(1).Values = rngRow
ThisWorkbook.Theme.ThemeColorScheme.Load GetColorScheme(thmColor)
chtMarker.Parent.CopyPicture xlScreen, xlPicture
lngPointIndex = lngPointIndex + 1
chtMain.SeriesCollection(1).Points(lngPointIndex).Paste
thmColor = thmColor + 1
Next
lngPointIndex = 0
Application.ScreenUpdating = True
End Sub
Function GetColorScheme(i As Long) As String
Const thmColor1 As String = "C:\Program Files\Microsoft Office\Document Themes 14\Theme Colors\Blue Green.xml"
Const thmColor2 As String = "C:\Program Files\Microsoft Office\Document Themes 14\Theme Colors\Orange Red.xml"
Select Case i Mod 2
Case 0
GetColorScheme = thmColor1
Case 1
GetColorScheme = thmColor2
End Select
End Function
The code tries to create a bubble chart with pie charts as the bubbles. As in this version colour themes are used to create a different colour in each pie chart (bulbble). However si there any way to do this without colour themes. I have been ointed to Collection object to do this but do not know how to implement this into the code. I suppose I woudl have to change the function part of the above code?
Updated code
Sub PieMarkers()
Dim srs As Series
Dim pt As Point
Dim p As Long
Dim c As Long
Dim col As Long
Dim chtMarker As Chart
Dim chtMain As Chart
Dim intPoint As Integer
Dim rngRow As Range
Dim lngPointIndex As Long
Dim thmColor As Long
Dim myTheme As String
Application.ScreenUpdating = False
Set chtMarker = ActiveSheet.ChartObjects("chtMarker").Chart
Set chtMain = ActiveSheet.ChartObjects("chtMain").Chart
Set chtMain = ActiveSheet.ChartObjects("chtMain").Chart
Set rngRow = Range(ThisWorkbook.Names("PieChartValues").RefersTo)
Set srs = chtMarker.SeriesCollection(1)
For Each rngRow In Range("PieChartValues").Rows
c = c + 1
srs.Values = rngRow
For p = 1 To srs.Points.Count
Set pt = srs.Points(p)
With pt.Format.Fill.ForeColor
col = p + (srs.Points.Count * c)
If col = 1 Then .RGB = 113567
If col = 2 Then .RGB = 116761
If col = 3 Then .RGB = 239403
If col = 4 Then .RGB = 398394
'etc.
'etc.
'## Add more IF statements to assign more colors.
If col = 24 Then .RGB = 1039834
End With
Next
chtMarker.Parent.CopyPicture xlScreen, xlPicture
lngPointIndex = lngPointIndex + 1
chtMain.SeriesCollection(1).Points(lngPointIndex).Paste
Next
lngPointIndex = 0
Application.ScreenUpdating = True
End Sub
so i can compile the lower bit of code without an error the problem is that the chart is afterwards only coloured in two colours (not 5 as as specified in the code). There are 8 pie charts, each of which has three different segments. Each segment (24 in total) shoudl have a different colour which is indicatable by an RGB value as in the first answer