values = srs.values
这里是下面的代码。
Sub AdjustWaterfallYAxis()
Dim ws As Worksheet
Dim cht As ChartObject
Dim srs As Series
Dim minValue As Double
Dim maxValue As Double
Dim newMin As Double
Dim newMax As Double
Dim i As Integer
Dim values As Variant
Dim cell As Range
' Loop through each worksheet
For Each ws In ThisWorkbook.Worksheets
' Loop through each chart object in the worksheet
For Each cht In ws.ChartObjects
' Check if the chart is a waterfall chart
If cht.Chart.ChartType = xlWaterfall Then
' Initialize min and max values
minValue = Application.WorksheetFunction.Min(ws.Range("A1:A10").Value)
maxValue = Application.WorksheetFunction.Max(ws.Range("A1:A10").Value)
' Loop through each series in the chart
For Each srs In cht.Chart.SeriesCollection
values = srs.Values
For Each cell In ws.Range(values.Address)
If cell.Value < minValue Then
minValue = cell.Value
End If
If cell.Value > maxValue Then
maxValue = cell.Value
End If
Next cell
Next srs
' Calculate new Y-axis range
newMin = minValue * 0.95
newMax = maxValue * 1.05
' Set new Y-axis range
With cht.Chart.Axes(xlValue)
.MinimumScale = newMin
.MaximumScale = newMax
End With
End If
Next cht
Next ws
End Sub
wape。
srs.Values
在瀑布图中,
srs.Values
返回错误,“对象不支持此操作”要找到图表系列的数据范围,您需要解析系列公式。看起来像=系列(Sheet1!$ C $ 2,Sheet1!$ B $ 3:$ B $ 7,Sheet1!$ C $ 3:$ C $ 7,1) 这意味着
中阅读有关此的信息。
通常,您可以使用srs.Formula
获得系列公式。将公式按逗号分开,您可以提取范围。
srs.Formula
返回与
srs.Values
的相同错误。
您仍然可以通过直接对数据范围进行采样,忽略图表中的内容。与常规图表不同,您必须知道数据范围在哪里,因为Excel Waterfall无法告诉您。