Activesheet and Chartobjects

Flyingmeatball

Board Regular
Joined
Aug 15, 2007
Messages
65
I've been trying to improve my understanding of the VBA I'm frequently using and I have a basic question about chartobjects. When I select a cell or a range, I can simply say write Cells(x,y).value, or range("A1").value and it will automatically select the cell on the activesheet.

When I try and select a chart however, it requires me to give:
Activesheet.chartObjects("Chart 1")
Why is this?

Also, why does it require ChartObjects("chart 1").chart.chartType?

Here's the code I wanted to shorten and what I thought I logically would shorten it to:

ActiveSheet.ChartObjects("Chart 1").Chart.ChartType = xl3DPieExploded
ChartObjects("Chart 1").ChartType = xl3DPieExploded

Can anyone explain why I need the .chart before the ChartType?

Thanks!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I shouldn't be sharing this with anyone who seriously wants to make a 3D exploded pie chart, but anyway...

A Chart can be either a chart on a standalone chart sheet (not a worksheet, which has rows and columns and cells and stuff), or a chart that is embedded in a sheet (chart sheet or more commonly worksheet). The chart is embedded by placing it within a shape which sits in the sheet. This shape is the ChartObject.

When changing the position or size of the chart, the ChartObject is what must be manipulated. The ChartObject sits between sheet and chart in the object model hierarchy, resulting in the syntax you've observed.
 
Upvote 0
Haha I'm putting together a demo for some coworkers of how to use simple macros , and I wanted to demonstrate that you could alter chart layouts with macros controlled by buttons - that's the only reason I selected piechart I swear! Thanks for your help though, that makes more sense now.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top