Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何在VBA中将图表标题设置为选定列_Excel_Vba_Charts_Title - Fatal编程技术网

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

Excel 如何在VBA中将图表标题设置为选定列,excel,vba,charts,title,Excel,Vba,Charts,Title,VBA新手,不确定如何将图表标题设置为特定的选定列。我正在从一个数据表中创建多个图形,以便能够选择要适当命名的数据和图形 Sub Charter() Dim my_range As Range Set my_range = Selection ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select ActiveChart.FullSeriesCollection(1).ChartType =

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=xlxyStrict


谢谢

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

ActiveChart.ChartTitle.Text = ActiveSheet.Cells(1, 1).Text
如果要使用
FullSeriesCollection(1)
的名称,则:

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

(通常,避免使用VBA-

ActiveChart中的
Select
ActiveChart

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

ActiveChart.ChartTitle.Text = ActiveSheet.Cells(1, 1).Text
如果要使用
FullSeriesCollection(1)
的名称,则:

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

(一般来说,请避免使用VBA-

中的
Select
ActiveChart

谢谢,但是您知道如何设置它,以便图表标题取自
ActiveChart.FullSeriesCollection(1)中使用的数据。ChartType=xlXYScatter
@ZacEpstein-我不明白您的意思“在
ActiveChart.FullSeriesCollection(1)中使用的数据。ChartType=xlxyStrict
xlxyStrict
是集合的图表类型,它不是数据。我希望图表标题是我选择的第三列数据,图表Legend中散点图名称中使用的相同数据我希望它与图表Legend中的系列2具有相同的名称legend@Zacchini-
ActiveChart.ChartTitle.Text=ActiveChart.FullSeriesCollection(1)。Name
这应该有效谢谢,但是您知道如何设置它,以便图表标题取自
ActiveChart.FullSeriesCollection(1)中使用的数据。ChartType=xlxyStrict
@ZacEpstein-我不明白您所说的“ActiveChart.FullSeriesCollection(1)中使用的数据”是什么意思.ChartType=xlxyStrict
xlxyStrict
是集合的图表类型,它不是数据。我希望图表标题是我选择的第三列数据,与图表Legend中散点图名称中使用的数据相同。我希望它与legend@Zacchini-
ActiveChart.ChartTitle.Text=ActiveChart.FullSeriesCollection(1)。Name
应该可以使用