Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA refer to chart name

Tags:

vba

Why this does not work:

ActiveSheet.ChartObjects("Sale").Axes(xlValue).MinimumScale = 1000

while this does:

  With ActiveChart.Axes(xlValue, xlPrimary)
    .MinimumScale = 1000
  End With

First I did this:

ActiveChart.Parent.Name="Sale"

I was not able to do this:

ActiveChart.Name="Sale"

I want to refer specifically to the chart "Sale", not to ActiveChart.

like image 991
Przemyslaw Remin Avatar asked Aug 03 '16 16:08

Przemyslaw Remin


People also ask

How do I find the chart object name in Excel?

On the right side of the Format ribbon, click Selection Pane. This pops out a menu bar on the right side of the worksheet. This bar lists all the charts on the current sheet. A slow double-click opens the chart name in a textbox, and you can rename it.

How do you add a name to a chart?

Click the chart, and then click the Chart Design tab. Click Add Chart Element > Chart Title, and then click the title option that you want. Type the title in the Chart Title box. To format the title, select the text in the title box, and then on the Home tab, under Font, select the formatting that you want.


1 Answers

A ChartObject is just a "container" for a Chart on a worksheet: you need to access its Chart property to get to the chart itself:

ActiveSheet.ChartObjects("Sale").Chart.Axes(xlValue).MinimumScale = 1000
like image 154
Tim Williams Avatar answered Nov 12 '22 09:11

Tim Williams