是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
谢谢
ActiveChart.ChartTitle.Text
是文本所需的属性。这是在ActiveChart
中引用它的一种方式:
ActiveChart.ChartTitle.Text = ActiveSheet.Cells(1, 1).Text
如果使用FullSeriesCollection(1)
的名称,则:
ActiveChart.ChartTitle.Text = ActiveChart.FullSeriesCollection(1).Name
(通常,避免在VBA中使用Select
和ActiveChart
-How to avoid using Select in Excel VBA]