Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 1.2 KB

File metadata and controls

28 lines (20 loc) · 1.2 KB

MS Excel Objects

Chart Objects

The ChartObject acts as a container for a Chart on a given worksheet.

Reference any ChartObject or corresponding Chart through the ChartObjects collection:

Worksheets("Sheet1").ChartObjects.Count ' --> 2
Worksheets("Sheet1").ChartObjects(1).Name ' --> Chart 1
Worksheets("Sheet1").ChartObjects(1).Chart.Name ' --> Sheet 1 Chart 1
Worksheets("Sheet1").ChartObjects(1).Chart.HasTitle ' --> True
Worksheets("Sheet1").ChartObjects(1).Chart.ChartTitle.Text ' --> My Pie Chart
Worksheets("Sheet1").ChartObjects(1).Chart.ChartType ' --> 5 (number corresponds to a Pie Chart)

When using the ChartType property, reference this list of corresponding Chart Types.

Once you have learned about loops, you can loop through each chart in the collection:

Dim MyChart as ChartObject

For Each MyChart In Worksheets("Sheet1").ChartObjects
  MsgBox(MyChart.Name & " (" & MyChart.Chart.ChartType & ")")
Next MyChart