如何将图表标题设置为VBA中的选定列

问题描述 投票:1回答:1

是VBA的新增功能,不确定如何将图表标题设置为特定的选定列。我正在从一个数据表中创建多个图形,因此希望能够选择要适当命名的数据和图形。

Sub Charter()

    Dim my_range    As Range

    Set my_range = Selection
    ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
    ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered
    ActiveChart.FullSeriesCollection(1).AxisGroup = 1
    ActiveChart.FullSeriesCollection(2).ChartType = xlLine
    ActiveChart.FullSeriesCollection(2).AxisGroup = 1
    ActiveChart.FullSeriesCollection(1).ChartType = xlXYScatter
    ActiveChart.FullSeriesCollection(1).AxisGroup = 1
    ActiveChart.SetSourceData Source:=my_range

    Cells(1, 1).Select

End Sub

我希望图形标题使用在ActiveChart.FullSeriesCollection(1).ChartType = xlXYScatter

谢谢

excel vba charts title
1个回答
0
投票

ActiveChart.ChartTitle.Text是文本所需的属性。这是在ActiveChart中引用它的一种方式:

ActiveChart.ChartTitle.Text = ActiveSheet.Cells(1, 1).Text

如果使用FullSeriesCollection(1)的名称,则:

ActiveChart.ChartTitle.Text = ActiveChart.FullSeriesCollection(1).Name

(通常,避免在VBA中使用SelectActiveChart-How to avoid using Select in Excel VBA]

© www.soinside.com 2019 - 2024. All rights reserved.