2015-04-06 37 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"

如果你想用图表进行实验,我建议使用宏录制。这就是我如何做到的。