0

我有一个按钮可以激活一个宏,该宏只是从表中创建一个图形。问题是当我按下宏按钮来创建图表时,它会将图表放在数据上。我希望宏将图形放在 K475 上。我应该在代码中添加什么?

Sub makeagraph()
'
' makeagraph îà÷øå
' makes a new graph for the table
'
' ÷éöåø î÷ùéí: Ctrl+g
'
   ActiveWindow.SmallScroll ToRight:=2
   Range("H473:I478").Select
   ActiveWindow.SmallScroll ToRight:=-3
   ActiveSheet.Shapes.AddChart2(251, xlPie).Select
   ActiveChart.SetSourceData Source:=Range("k$473:$I$478")
   ActiveChart.ClearToMatchStyle
   ActiveChart.ChartStyle = 253
End Sub
4

1 回答 1

0

请尝试下一个方法:

Sub CreateChartPositioning()
   ActiveSheet.Shapes.AddChart2(251, xlPie).Select
   ActiveChart.SetSourceData SOURCE:=Range("k$473:$I$478")
   ActiveChart.ClearToMatchStyle
   ActiveChart.ChartStyle = 253
   With Range("K475")
        ActiveChart.Parent.top = .top
        ActiveChart.Parent.left = .left
   End With
   Debug.Print ActiveChart.Parent.TopLeftCell.Address 'only to prove its position (in Immediate Window)
End Sub

您的代码必须设置创建图表的放置位置。TopLeftCellReadOnly财产...

于 2022-01-15T16:11:33.147 回答