我在堆积区域图表中绘制了以下数据网格,我想将任何负变量作为辅助轴变量
Year | var 1 | var 2 | var 3 |
------ | ------ | ------ | ------ |
2012 | 73.97% | 7.70% | -0.86% |
2013 | 74.49% | 7.46% | -0.76% |
2014 | 73.60% | 7.48% | -0.82% |
2015 | 71.87% | 7.01% | -0.75% |
2016 | 64.96% | 5.18% | -0.75% |
我已将以下VBA放在一起,我已将其分配给与我的堆积区域图相同的选项卡上的开发人员按钮,但我不断得到错误,说没有定义SeriesCollection函数。有任何想法吗?理想情况下,堆积面积图将位于其自己的选项卡中:
Sub TesNegs()
Dim n As Series
ActiveChart.PlotArea.Select
For Each n In ActiveChart.SeriesCollection
If Application.WorksheetFunction.Max(ActiveChart.SeriesCollection(n).Values) < 0 Then
n.AxisGroup = 2
End If
Next n
End Sub
答案 0 :(得分:0)
Dim n As Series
ActiveChart.PlotArea.Select
' set any negative series to the secondary axis
For Each n In ActiveChart.SeriesCollection
Dim Max As Double
Max = 0
For Each Value In n.Values
If Value > Max Then
Max = Value
End If
Next Value
If Max = 0 Then
n.AxisGroup = 2
End If
Next n