我正在尝试创建一个宏,其中创建的图表具有列的动态范围。这是我到目前为止所拥有的。
Private Sub CommandButton2_Click()
With Sheets("Sheet1")
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=.Range("D2", Cells(2, N + 3))
ActiveChart.Location xlLocationAsObject
End With
End Sub
但是现在,我一直在使用语句 -
遇到运行时错误“指定的维度对当前图表类型无效”
当我查看代码时,它会不断引用最后一行。
ActiveChart.Location xlLocationAsObject
有什么想法吗?感谢
关注
以下是引用N
的代码Dim N As Long
Private Sub CommandButton1_Click()
Dim x As Integer
Dim y As Integer
x = 0
y = 1
N = Application.InputBox(Prompt:="Enter value", Type:=1)
If N > Columns.Count Then
N = Columns.Count
Else
For i = 4 To 9999
Cells(1, i).ClearContents
Cells(3, i).ClearContents
Next i
End If
For i = 4 To N + 3
x = x + y
Cells(1, i) = x
Next i
End Sub
答案 0 :(得分:1)
xlLocationAsObject需要where
参数,指定要嵌入或放置图表对象的位置
替换
ActiveChart.Location xlLocationAsObject
带
ActiveChart.Location xlLocationAsObject, Name
将图表嵌入Sheet1
查看所有可用选项