用于绘制备用列的两个单独图表的VBA代码

时间:2015-07-01 11:16:12

标签: excel vba

This是我拥有的大数据集的一部分。我想为' Actual'绘制两个单独的图表。和'总数'。

这是我目前的代码:

Private Sub CommandButton2_Click()
Dim ChartRange1 As Range
Dim ChartRange2 As Range

`StrtRow = 1
 StartRow = 3
 EndRow = 6

With Sheets("Sheet1")

Set ChartRange1 = Range(Cells(StrtRow, "B"), Cells(EndRow, "B"))
ChartRange1Addr = ChartRange1.Address(External:=True)

 Set ChartRange2 = Range(Cells(StrtRow, "C"), Cells(EndRow, "J"))
ChartRange2Addr = ChartRange2.Address(External:=True)
End With

ActiveSheet.Shapes.AddChart.Select

'We set the source data for the chart (y,x)


ActiveChart.SetSourceData Source:=Range( _
ChartRange1Addr & "," & ChartRange2Addr)


'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("Sheet1").Select
' we select the cell F9 in sheet1
    Range("F9").Activate

End Sub

它给出了同一图表中的实际和%图。我已经尝试过选择备用列和绘制两个图表的代码,但它没有用。

This是我得到的图表。请建议我在哪里修改我的代码,为备用列创建两个单独的图表 - 一个用于'实际'和另外一个'%'%值。

0 个答案:

没有答案