VBA 更改图表中的数据标签 - 兼容性 btw Excel 2013 和 2010

VBA to change data label in a chart - Compatibility btw Excel 2013 and 2010

我做了一个宏来更改仪表板中图表标签的数字格式,因为值可以是数千或数百万。在我的代码中,我已经将仅存在于 Excel 2013 年及之后的对象 FullSeriesCollection 更改为 SeriesCollection。但是,当我 运行 2010 年 Excel 中的代码时,我仍然面临问题,因为自定义数字格式代码带来了完全不同的结果。

关注 VBA 数百万

    Sheets("Gráficos").ChartObjects("n2_resultado").Activate
ActiveChart.SeriesCollection(1).DataLabels.Select
    Selection.NumberFormat = "#.##0,0..;-#.##0,0..;"""""
ActiveChart.SeriesCollection(2).DataLabels.Select
    Selection.NumberFormat = "#.##0,0..;-#.##0,0..;"""""
ActiveChart.SeriesCollection(3).DataLabels.Select
    Selection.NumberFormat = "#.##0,0..;-#.##0,0..;"""""
ActiveChart.SeriesCollection(4).DataLabels.Select
    Selection.NumberFormat = "#.##0,0..;-#.##0,0..;"""""
ActiveChart.SeriesCollection(5).DataLabels.Select
    Selection.NumberFormat = "#.##0,0..;-#.##0,0..;"""""
ActiveChart.SeriesCollection(6).DataLabels.Select
    Selection.NumberFormat = "#.##0,0..;-#.##0,0..;"""""

对于千值,数字格式代码是这样的:

"#.##0,0.;-#.##0,0.;"""""

我无法轻松访问 Excel 2010,但昨天一瞥,似乎我们在前台使用的代码在后台不起作用-房子。

有什么办法可以解决吗?

注意:"Gráficos" 是葡萄牙语中 "Chart" 的意思,在巴西,我们使用点作为千位分隔符,使用逗号表示小数(世界上大部分地区的反义词 lol)

This is the messy chart I got

Excel 2010 年和 2013 年在宏中的数字格式代码方面似乎有所不同。由于我对 Excel 2010 的访问受限,解决方案是复制图表,根据需要更改标签,然后切换宏以仅显示带有 millions/thousands 标签的图表。