Looping through the Chart Objects collection

Vertex42 The Excel Nexus

Professional Excel Templates

Get Instant Access

This example changes the chart type of every embedded chart on the active sheet. The procedure uses a For-Next loop to cycle through each object in the ChartObjects collection, access the Chart object in each, and change its Type property.



Dim cht As ChartObject

For Each cht In ActiveSheet.ChartObjects

cht.Chart.Type = xlArea

Next cht



The following macro performs the same function but works on all the chart sheets in the active workbook:

Sub ChartType2()

Dim cht As Chart

For Each cht In ActiveWorkbook.Charts cht.Type = xlArea Next cht End Sub

Was this article helpful?

+1 0

Post a comment