Excel Waterfall Charts: Unable to resize plot/legend areas in VBA generated waterfall charts

1.2k views Asked by At

I have a VBA function in Excel (office 365 ProPlus) generating waterfall charts, see examples below. After generating them I want to resize the plot/legend/axis areas just to adjust the looks.

But Excel doesn't let me; the edges of the areas seem to be fixed (see blue dots/circles), I can't grab them. I can change the axis ranges but not the area sizes. If I change the chart type e.g. to stacked bars it works.

The sheet is not protected.

Is this a known problem?

Is there a workaround?

Do I have something in my code (below) that causes this behaviour, or is something missing?

2 waterfall charts - plot area

    Dim rngChartValues          As Range
    Dim rngChartXValues         As Range
    Dim myChart                 As Chart
    Dim myShape                 As Shape
    Dim dStartValue             As Double
    Dim dEndValue               As Double
    Dim dDeltaSurplus           As Double
    Dim dDeltaPC                As Double
    Dim chartTitle              As String
    Dim rngToplace              As Range

    rngChartValues.Select
    Set myShape = ActiveSheet.Shapes.AddChart2(395, xlWaterfall)
    Set myChart = myShape.Chart 'ActiveChart
    
    Application.CutCopyMode = False
    rngToplace.Select
    
    With myShape
        .Left = rngToplace.Left
        .Top = rngToplace.Top
        .Placement = xlFreeFloating
        .Height = 450
    End With
    
    With myChart
        .Legend.Delete
        .chartTitle.Text = chartTitle
        .SeriesCollection.NewSeries
        .Parent.name = chartTitle
        With .FullSeriesCollection(1)
            
            .name = chartTitle
            .Values = rngChartValues
            .XValues = rngChartXValues
            
            dStartValue = shtCharts.Cells(rowCapSurplusEarlr, colCA).Value
            dEndValue = shtCharts.Cells(rowCapSurplusLater, colCA).Value
            dDeltaSurplus = shtCharts.Cells(rowDeltaSurplus, colCA).Value
            dDeltaPC = Abs(dDeltaSurplus / dStartValue)
            
            ' handle the last bar as total bar
            With .Points(.Points.Count)
                .IsTotal = True
                If dDeltaPC < 0.1 Then                                          ' change is smaller than 10%
                    If dDeltaSurplus < 0 Then                                   ' ...but still negative
                        .Format.Fill.ForeColor.RGB = RGB(255, 204, 0)           '   => light orange
                    Else                                                        ' ... and positive
                        If dEndValue < 0 Then                                   '   ... but the surplus is till negative
                            .Format.Fill.ForeColor.RGB = RGB(255, 204, 0)       '       => light orange
                        Else                                                    ' ... and the surplus is positive
                            .Format.Fill.ForeColor.RGB = RGB(153, 204, 0)       '   => light green
                        End If
                    End If
                ElseIf dDeltaSurplus < 0 Then                                   ' change is >10% and negative
                    .Format.Fill.ForeColor.RGB = RGB(255, 153, 0)               '   => orange
                Else                                                            ' cange is >10$ and positive
                    If dEndValue < 0 Then                                       ' ... but the surplus is till negative
                        .Format.Fill.ForeColor.RGB = RGB(255, 255, 0)           '   => yellow
                    Else                                                        ' ... and the surplus is positive
                        .Format.Fill.ForeColor.RGB = RGB(0, 160, 0)             '   => green
                    End If
                End If
                
            End With
        End With
    End With
    
    With myChart.Parent
        intTmp = .Width
        intTmp = .Height
    End With
0

There are 0 answers