Excel 如何获取轴标签中的颜色

Excel 如何获取轴标签中的颜色,excel,excel-2007,vba,Excel,Excel 2007,Vba,我对透视图有问题。将数据标签应用于我的图表,我选择数据标签并打开“设置数据标签格式”窗口,转到“数字”选项卡。选择“自定义”,代码如下:[黑色]+0%;[红色]-0%将正值格式化为黑色,将负值格式化为红色。 那么,如何在宏excel中进行编码呢 非常感谢您提供的任何帮助。试试这个: Sub format_datalabel() Dim my_series As Series Dim pt As Point 'change the chart name and update the Serie

我对透视图有问题。将数据标签应用于我的图表,我选择数据标签并打开“设置数据标签格式”窗口,转到“数字”选项卡。选择“自定义”,代码如下:[黑色]+0%;[红色]-0%将正值格式化为黑色,将负值格式化为红色。 那么,如何在宏excel中进行编码呢

非常感谢您提供的任何帮助。

试试这个:

Sub format_datalabel()

Dim my_series As Series
Dim pt As Point

'change the chart name and update the SeriesCollection number if you have more than 1 series in your chart
Set my_series = ActiveSheet.ChartObjects("Chart 1").Chart.SeriesCollection(1)

For Each pt In my_series.Points
    pt.DataLabel.NumberFormat = "[black] +0%; [red] -0%"
Next pt

End Sub
只需更改图表名称并运行代码。

此外,如果你的图表中有1个以上的序列,你也应该确定它。

我做到了!非常感谢你!