excel - 在动态 Excel 图中更改系列名称

标签 excel vba

我有一个动态图表,可以更改在 excel 中绘制的系列数量,但是,我想要一种将图例中的系列名称更改为我在不同工作表的其他单元格中的名称的方法。我有以下代码,但我不确定如何更改图表系列行中的字母;

Dim i As Integer
Dim No_of_probes As Integer

Sheets("1. Paste Raw Data").Select
No_of_probes = Range("A2").Value

For i = 1 To No_of_probes

ActiveChart.FullSeriesCollection(i).Name = "='1. Paste Raw Data'!$C$4"

Next i

我希望它像这样循环,对于 For 循环的每次传递都以相同的方式递增,但我不确定如何在最后更改字母或单元格引用?我发现很难在任何地方找到与此类似的示例。
    'ActiveChart.FullSeriesCollection(1).Name = "='1. Paste Raw Data'!$C$4"
    'ActiveChart.FullSeriesCollection(2).Name = "='1. Paste Raw Data'!$D$4"
    'ActiveChart.FullSeriesCollection(3).Name = "='1. Paste Raw Data'!$E$4"
    'ActiveChart.FullSeriesCollection(4).Name = "='1. Paste Raw Data'!$F$4"
    'ActiveChart.FullSeriesCollection(5).Name = "='1. Paste Raw Data'!$G$4"
    'ActiveChart.FullSeriesCollection(6).Name = "='1. Paste Raw Data'!$H$4"
   ' ActiveChart.FullSeriesCollection(7).Name = "='1. Paste Raw Data'!$I$4"
    'ActiveChart.FullSeriesCollection(8).Name = "='1. Paste Raw Data'!$J$4"
    'ActiveChart.FullSeriesCollection(9).Name = "='1. Paste Raw Data'!$K$4"
    'ActiveChart.FullSeriesCollection(10).Name = "='1. Paste Raw Data'!$L$4"
    'ActiveChart.FullSeriesCollection(11).Name = "='1. Paste Raw Data'!$M$4"
    'ActiveChart.FullSeriesCollection(12).Name = "='1. Paste Raw Data'!$N$4"
    'ActiveChart.FullSeriesCollection(13).Name = "='1. Paste Raw Data'!$O$4"

最佳答案

这可以用来:

Dim i As Integer
Dim No_of_probes As Integer

Sheets("1. Paste Raw Data").Select
No_of_probes = Range("A2").Value

For i = 1 To No_of_probes

    ActiveChart.FullSeriesCollection(i).Name = "='1. Paste Raw Data'!" & Range("C4").Offset(0, i - 1).Address

Next i

关于excel - 在动态 Excel 图中更改系列名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60060788/

相关文章:

C# 访问 EXCEL,将单元格格式设置为常规

c# - 在内存中打开 XML 字符串作为 Excel 工作簿而不使用 Windows 窗体 C# 保存

excel - 接收运行时错误 58 文件已存在但不存在

excel - 为什么在使用 For Each Next 循环之前不需要设置对象变量?

excel - CSV 文件创建,如 unicodetext、endig .csv。 VBA 无法打开、保存和关闭更改

excel - 删除重复项,但尊重案例

vba - 无法解析位于 iframe 中的某些链接

excel - 使用 VBA 替换字符串中特定位置的文本

vba - 从 VBA Excel 在 dos 命令中运行 7Z 会导致警告警报

excel - 拆分字段内容和重复行