错误的表VBA中的堆积条形图

时间:2017-02-16 17:19:05

标签: vba excel-vba excel

我正在尝试在vba中创建一个图表但是当我尝试将图表输入到特定工作表时它不会让我,这是我的代码:

Sub orange_weightings_chart()

Dim MyChtObj As ChartObject
Dim Sht1 As Worksheet
Dim Sht2 As Worksheet
Dim Sht1Name As String
Dim Sht2Name As String

Set Sht2 = Worksheets("Orange Weightings")
Set Sht1 = Worksheets("Weightings Table")
Sht1Name = Sht1.Name
Sht2Name = Sht2.Name
Set MyChtObj = Sht1.ChartObjects.Add(100, 100, 500, 500)

With MyChtObj.Chart
    .ChartType = xlBarStacked
End With

With MyChtObj
    .Top = Sht2.Range("E15").Top
    .Left = Sht2.Range("E15").Left
End With

End Sub

现在图表会存入Sht1或“权重表”而不是Sht2。为什么会这样,我怎样才能进入正确的表格。我用折线图尝试了完全相同的方法并且它有效(注意我省略了不相关的代码)。

0 个答案:

没有答案