VBA:如何知道图表是否在单独的工作表中? [英] VBA: How to know if chart is in separate sheet?
本文介绍了VBA:如何知道图表是否在单独的工作表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在VBA中访问一系列基础数据的格式?像这样:
How can I access the format of the underlying data of a series in VBA? Something like this:
If ActiveChart.SeriesCollection(1).UnderlyingXValues.NumberFormat = "m/d/yy" Then
ActiveChart.Axes(xlValue).TickLabels.NumberFormat = "mmm yyyy"
Else If ActiveChart.SeriesCollection(1).UnderlyingXValues.NumberFormat = "0" Then
ActiveChart.Axes(xlValue).TickLabels.NumberFormat = "0.0"
End If
上面的示例中是否有类似UnderlyingXValues的东西?
Is there something that works like UnderlyingXValues in the example above?
推荐答案
您可以解析 SeriesCollection
的 .Formula
,如下所示:
You can parse the .Formula
of the SeriesCollection
, like this:
Sub Test()
Dim seriesFormula As String
seriesFormula = ActiveChart.SeriesCollection(1).Formula
Dim seriesAddress As String
seriesAddress = Split(seriesFormula, ",")(2)
Dim seriesRng As Range
Set seriesRng = Range(seriesAddress)
Select Case seriesRng.NumberFormat
Case "m/d/yy"
ActiveChart.Axes(xlValue).TickLabels.NumberFormat = "mmm yyyy"
Case "0"
ActiveChart.Axes(xlValue).TickLabels.NumberFormat = "0.0"
End Select
End Sub
正如已经指出的那样,源范围的数字格式必须一致才能起作用.
As already pointed out, the number formatting of the source range must be consistent for this to work.
这篇关于VBA:如何知道图表是否在单独的工作表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文