2015-04-06 40 views
0
Dim LastRow As Long 
Dim Rng1 As Range 
Dim ShName As String 
With ActiveSheet 
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row 
    Set Rng1 = .Range("A2:E" & LastRow) 
    ShName = .Name 
End With 

Charts.Add 
With ActiveChart 
    .ChartType = xlLine 
    .HasTitle = True 
    .ChartTitle.Text = "CPU Utilization" 
    .Axes(xlCategory, xlPrimary).HasTitle = True 
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Duration of Run(hh:mm)" 'X axis name 
    .Axes(xlValue, xlPrimary).HasTitle = True 
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "CPU Utilization (%)" 'y-axis name 
    .Legend.Position = xlLegendPositionBottom 
    .SetSourceData Source:=Rng1 
    .Location Where:=xlLocationAsObject, Name:=ShName 

End With 

我想在上面的代碼中,我試圖下面的代碼,但did'nt工作(的方法或數據未找到錯誤)在Excel VBA中獲取的NumberFormat

.NumberFormat = "[$-F400]h:mm:ss AM/PM" 
.NumberFormat = "h:mm;@" 

也希望設置的寬度和高度的NumberFormat添加的圖形並在格式軸上添加千個顯示單位。請。爲此提供解決方案。

回答

0

對於數字格式,您必須將數字格式分配給圖表的一些。例如:Axes(xlCategory).TickLabels.NumberFormat
對於間隙寬度請參閱MSDN-ChartGroup.GapWidth Property
我不明白你怎麼想顯示數千時間格式,但對於千個分隔值自定義格式看起來像這樣"# ##0,00"

如果你想用圖表進行實驗,我建議使用宏錄製。這就是我如何做到的。