简体   繁体   English

在Excel VBA中获取Numberformat

[英]Get Numberformat in excel vba

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

I want to add numberformat in above code i tried below code but did'nt work(Method or Data not Found Error) 我想在上面的代码中添加数字格式,我在下面的代码中尝试了但没有用(方法或数据未找到错误)

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

also want to set width and height of the graph and add display units thousand in format axis. 还希望设置图形的宽度和高度,并在格式轴中添加显示单位千。 pls. provide solution for same. 提供相同的解决方案。

For the Number format , you must assign the number format to some child of the chart. 对于数字格式 ,您必须将数字格式分配给图表的某些子级 For example : Axes(xlCategory).TickLabels.NumberFormat 例如: Axes(xlCategory).TickLabels.NumberFormat
For Gap width see MSDN-ChartGroup.GapWidth Property . 有关间隙宽度,请参见MSDN-ChartGroup.GapWidth属性
I don't understand how you want to display thousands in time format, but the custom format for thousand separated values looks like this "# ##0,00" 我不明白您想如何以时间格式显示数千,但千位分隔值的自定义格式如下所示: "# ##0,00"

If you want to experiment with charts, I recommend using macro recorder. 如果要试验图表,建议使用宏记录器。 That's how I got to this. 这就是我的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM