我想用excel vba創建堆積柱狀圖。 input data創建堆積柱狀圖的問題
以下提到的是我的excel vba代碼,用於爲相應的輸入數據生成堆棧柱狀圖。
Sub to_draw_chart()
ActiveSheet.Shapes.AddChart2(297, xlColumnStacked).Select
ActiveChart.SetSourceData Source:=Range("Sheet2!$A$1:$P$4")
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MaximumScale = 1000
ActiveChart.Axes(xlValue).MajorUnit = 250
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).CategoryType = xlCategoryScale
ActiveChart.Axes(xlCategory).CategoryType = xlAutomatic
Application.CommandBars("Format Object").Visible = False
ActiveChart.FullSeriesCollection(2).Select
ActiveChart.Axes(xlCategory).CategoryType = xlCategoryScale
Selection.Format.Fill.Visible = msoFalse
ActiveChart.FullSeriesCollection(5).Select
Selection.Format.Fill.Visible = msoFalse
ActiveChart.FullSeriesCollection(12).Select
Selection.Format.Fill.Visible = msoFalse
ActiveChart.FullSeriesCollection(15).Select
Selection.Format.Fill.Visible = msoFalse
ActiveChart.ChartArea.Select
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Chart "
Selection.Format.TextFrame2.TextRange.Characters.Text = "Chart "
End Sub
outputExpected_VS_output_getting
但是當我運行這個宏,我得到的輸出是不同的。問題出在x軸上。我的X軸應該是D0,D1,D2(正如你可以在圖像「Output Expected」中看到的那樣,但是它不同,我也附加了當我運行vba代碼時得到的輸出(第二幅圖像)
我不理解爲什麼我的X軸得到改變這確實影響了代碼和輸出圖形。
手動當我不使用代碼,然後我得到正確的輸出做。
我要去哪裏錯誤?
看到我的答案在下面(另一個選項來處理圖表對象) –
是的,它的工作。非常感謝你。 – user28
然後請upvote和標記爲答案 –