2014-01-10 68 views
0

我試圖在顯示12月份2012年月數據的圖表的宏Excel中製作程序。根據範圍的大小,圖表返回不同的結果

我想要X軸是月份,但僅在1月份,軸線n圖例切換。

我的代碼:

Public Sub pi() 

    Dim bulan1 
    Dim bulan2 
    Dim kpi As Worksheet 
    Dim data As Worksheet 
    Dim a As Integer 
    Dim x As Integer 
    Dim xaxis As Axis 


    Set kpi = ThisWorkbook.Sheets("KPI chart") 
    Set data = ThisWorkbook.Sheets("data") 

    bulan1 = Month(Now) 

    For a = 2 To 14 
     bulan2 = Month(Cells(54, a).Value) 

     If bulan2 = bulan1 Then 

     End If 
    Next 

    kpi.ChartObjects("Chart 16").Activate 
    ActiveChart.SetSourceData Source:=Range(data.Cells(54, 1), data.Cells(57, a)) 

End Sub 

圖片: http://melegenda.tumblr.com/image/72825632452

我想我錯過了什麼? (我使用excel 2007)

+1

This [SO question](http://stackoverflow.com/questions/21007443)可能對您有所幫助。 – PatricK

+0

有幫助。但不是這個問題:) –

+0

在for循環之後'a'總是15,你需要在If塊中退出條件'Exit For'。 – PatricK

回答

0

我不知道這是什麼,但它的工作原理。 ahhaha 只需添加ActiveChart.PlotBy = xlRows 之前end sub

相關問題