在VBA中使用variables绘图

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

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:

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

即使variables,如果它在“”之间,那么它变成了string。


例如,让我们说你的shtname是“Sheet1”

在你最后的尝试线上

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

基本上,你将XValues设置为

!= 'Sheet 1中' $ B $(C + 3):$ N $(C + 3)

尝试

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