下面是我尝试在excel VBA上运行的代码,但是尝试使用此宏时始终出现错误。
Sub Demand()
Range("E1").Select
ActiveCell.FormulaR1C1 = "demand"
Range("E1").Select
ActiveCell.FormulaR1C1 = "demand"
Range("E1").Select
ActiveCell.FormulaR1C1 = "demand"
Range("E1:E52").Select
ActiveSheet.Shapes.AddChart2(227, xlLineMarkers).Select
ActiveChart.SetSourceData Source:=Range("DATA!$E$1:$E$52")
ActiveSheet.Shapes("Chart 4").IncrementLeft 204
ActiveSheet.Shapes("Chart 4").IncrementTop -34
ActiveSheet.Shapes("Chart 4").ScaleHeight 1.4722222222, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 4").ScaleWidth 1.1111111111, msoFalse, _
msoScaleFromBottomRight
Application.CutCopyMode = False
End Sub
答案 0 :(得分:0)
修复:
Sub Demand()
Dim co, cht As Chart
Range("E1").Value = "demand"
Set co = ActiveSheet.Shapes.AddChart2(227, xlLineMarkers)
Set cht = co.Chart
cht.SetSourceData Source:=Range("DATA!$E$1:$E$52")
co.Left = Range("E2").Left 'for example
co.Top = Range("E2").Top
co.Height = 400
co.Width = 400
End Sub