通过macros在需要的位置粘贴graphics

我正在使用位置中的macros生成graphics。 但是,由于我生成了多个图表,所以它们彼此堆叠在一起。 我没有能够把他们正确地摆放在一起。 我该怎么做? 以下是我的代码:

Range("A318:A322,B318:B322").Select 'In the active sheet we add a chart ActiveSheet.Shapes.AddChart.Select ' We set the source data for the chart ActiveChart.SetSourceData Source:=Range( _ "'Assessment'!$A$318:$A$322,'Assessment'!$B$318:$B$322") 'We define the type of chart ActiveChart.ChartType = xlColumnClustered ' Before we can perform an action on the chart we need to activate it ActiveSheet.ChartObjects(1).Activate 'We perform the cut operation ActiveSheet.ChartObjects(1).Cut 'we select the Sheet2 where we wish to paste our chart 'Sheets("Sheet2").Select 'We now paste the chart in the Sheet2 whic has become the active sheet after selection 'ActiveSheet.Paste 'we return to sheet1 Sheets("User Report").Select ActiveSheet.Paste ' we select the cell F9 in sheet1 Range("D1").Activate 

我现在如何将图表粘贴到表格中所需的单元格中?

不需要select或激活:

 Dim co Set co = ActiveSheet.Shapes.AddChart() co.Chart.SetSourceData Source:=Range("'Assessment'!$A$318:$A$322,'Assessment'!$B$318:$B$322") co.Chart.ChartType = xlColumnClustered co.Cut With Sheets("Sheet2") .Paste Set co = .Shapes(.Shapes.Count) co.Left = .Range("D1").Left co.Top = .Range("D1").Top End With 

或者,将图表放在右侧的正确位置开始。

 Dim co As ChartObject Set co = Worksheets("Sheet2").Shapes.AddChart(Left:=Worksheets("Sheet2").Range("D2").Left, _ Top:=Worksheets("Sheet2").Range("D2").Top) co.Chart.SetSourceData Source:=Range("'Assessment'!$A$318:$A$322,'Assessment'!$B$318:$B$322") co.Chart.ChartType = xlColumnClustered