我正在尝试创建一个程序,将多个数据集加载到自己的工作表中,然后根据数据创建一个图表。我一直在努力获取图表的正确数据。我一直在使用计数器来标记我的数据集,因为它们被放在一张纸上。 我的工作表名称已定义为如下所示的字符串。程序在尝试获取数据时会收到错误..
Dim CurrentSheet is string
CurrentSheet = ActiveSheet.Name
Charts.Add
ActiveChart.SeriesCollection(1).Values = "=CurrentSheet!$C$2:$C$100000"
ActiveChart.SeriesCollection(1).XValues = "=CurrentSheet!$A$2:$A$100000"
答案 0 :(得分:0)
尝试:
Dim CurrentSheet As String
CurrentSheet = ActiveSheet.Name
Charts.Add
ActiveChart.SeriesCollection(1).Values = "=" & CurrentSheet & "!$C$2:$C$100000"
ActiveChart.SeriesCollection(1).XValues = "=" & CurrentSheet & "!$A$2:$A$100000"
稍后编辑
更好的是,处理工作表名称中包含白色字符的情况:
Dim CurrentSheet As String
CurrentSheet = ActiveSheet.Name
Charts.Add
ActiveChart.SeriesCollection(1).Values = "='" & CurrentSheet & "'!$C$2:$C$100000"
ActiveChart.SeriesCollection(1).XValues = "='" & CurrentSheet & "'!$A$2:$A$100000"