【问题标题】:Plot in VBA Using Variable使用变量在 VBA 中绘图
【发布时间】:2016-06-03 18:24:47
【问题描述】:

所以这是我正在使用的代码:

c = Application.Match("Test", Range("F1:F130"), 0)        
    ActiveChart.SeriesCollection(1).XValues = "='" & shtname & "'" &  "!$B$104:$N$104"

与我想说的情节非常相似,因为 c+4 = 一些整数,并不总是 104。

ActiveChart.SeriesCollection(1).XValues = "='" & shtname & "'" &  "!$B$(c+3):$N$(c+3)"

我尝试过使用类似的方法:

ActiveChart.SeriesCollection(1).XValues = "='" & shtname & "'" & "!$B$" & " (c+3):$N$" & " (c+3) "

这不起作用......显然,但我对 VBA 和语法非常陌生,因此感谢任何帮助。 这里也是 shtname 的函数:

    Function shtname() As String
    shtname = ActiveSheet.Name
    End Function

【问题讨论】:

  • 尝试 ActiveChart.SeriesCollection(1).XValues = "='" & shtname & "'!$B$" & (c+3) & ":$N$" & ( c+3)
  • @MutjayLee 这是一个行号
  • @MutjayLee 就像一个魅力,提交它作为答案,我会接受它

标签: excel vba


【解决方案1】:

偶数变量,如果在""之间就变成字符串了。


例如,假设您的 shtname 是“Sheet1”

在你的最后一次尝试行

ActiveChart.SeriesCollection(1).XValues = "='" & shtname & "'" & "!$B$" & " (c+3):$N$" & " (c+3) "

基本上,您将 XValues 设置为

='Sheet1'!$B$(c+3):$n$(c+3)

试试

ActiveChart.SeriesCollection(1).XValues = "='" & shtname & "'!$B$" & (c+3) & ":$N$" & (c+3)

【讨论】:

    猜你喜欢
    • 2011-05-24
    • 2016-10-10
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多