Starting debugging:
There are other references to charts in the code than in the sheet.
no chtPieMarker at all,
ChartObjects(1) is a pie chart while shall be chtMarker one
Correct to:
Set chtMarker = ActiveSheet.ChartObjects("chtMarker").Chart
' reference to chart that pie markers will be applied to
Set chtMain = ActiveSheet.ChartObjects("chtMain").Chart
This starts working, but causes an error because you run loop which is too long:
For Each rngRow In Range("F4:J11").Rows
while your data extends only to H7
Use only existing data:
For Each rngRow In Range(Range("F4"), Range("F4").End(xlToRight).End(xlDown)).Rows
This runs to the end but visual effect is not perfect, namely aspect ratio is wrong (ovals instead of circles pasted into main chart).
Either correct manually aspect ratio of whole chtMarker drawning area, or do it in the code.
Final: at the end of the code you again switch off screen updationg - it has no effect because: 1) is already switched off 2) once the code stops screen updating is switched on.
intPoint variable is unused
So the code at this stage (code is never final - probably still more debugging needed :-P ) could be:
Sub PieMarkers()
Dim chtMarker As Chart
Dim chtMain As Chart
Dim rngRow As Range
Dim lngPointIndex As Long
Application.ScreenUpdating = False
'make sure pie is drawn on square drawning area
With ActiveSheet.Shapes("chtMarker")
.LockAspectRatio = msoFalse
.ScaleWidth .Height / .Width, msoFalse, msoScaleFromTopLeft
.LockAspectRatio = msoTrue
End With
' reference to pie chart
Set chtMarker = ActiveSheet.ChartObjects("chtMarker").Chart
' reference to chart that pie markers will be applied to
Set chtMain = ActiveSheet.ChartObjects("chtMain").Chart
' pie chart data which will be processed by rows
For Each rngRow In Range(Range("F4"), Range("F4").End(xlToRight).End(xlDown)).Rows
' assign new values to pie chart
chtMarker.SeriesCollection(1).Values = rngRow
' copy pie
chtMarker.Parent.CopyPicture xlScreen, xlPicture
' paste to appropriate data point
lngPointIndex = lngPointIndex + 1
chtMain.SeriesCollection(1).Points(lngPointIndex).Paste
Next
' release objects
Set chtMarker = Nothing
Set chtMain = Nothing
Application.ScreenUpdating = True
End Sub
Bookmarks