Series line not correct after split

Schadenfreud

New Member
Joined
Jan 22, 2014
Messages
29
I'm using this code to split a series line into 2 overlapping parts, so I can use different styles on them:
Code:
Sub backfillDataSeries()
    'make new series in Port Historical Risk
    'if there is a backfill date in Rolling window data
Dim cRange As Range
Dim i As Integer


For i = 3 To 122
    Set cRange = Sheet24.Cells(i, 4) 'Sheet 24 - Rolling_window_data
    If IsNumeric(cRange.Value) And Not IsEmpty(cRange.Value) And Not IsError(cRange.Value) Then 'iterate through range D3:D122
        With Sheet49.ChartObjects("Chart 4").Activate
            With ActiveChart.SeriesCollection(1) 'Sheet 49 - Port Historical Risk
                .Values = "=Rolling_window_data!$B$3:$B$" & i
                .XValues = "=Rolling_window_data!$A$3:$A$" & i
            End With
            With ActiveChart.SeriesCollection.NewSeries
                .Values = "=Rolling_window_data!$B$" & i & ":$B$122"
                .XValues = "=Rolling_window_data!$A$" & i & ":$A$122"
                .Name = "Backfilled"
                .Format.Line.DashStyle = msoLineDash
                
            End With
        End With
        Exit For
    End If
Next i
End Sub
This is how the line looks before I run the code:
line.png


And this is how it looks afterwards:
statistics.png


I think it prints mirrored. Can I get a mirror image of the 2nd line?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I figured out why it's mirrored - it was because it should be on the secondary Axis and it was on the primary one, but now both lines start from the left-most part of the chart, which shouldn't be the case.
 
Upvote 0
After a tough battle I achieved the desired effect. Turns out you have to have 2 data columns, both with some blank values, to achieve the desired overlap effect.

Code:
Sub backfillDataSeries()
    'make new series in Port Historical Risk
    'if there is a backfill date in Rolling_window_data
Dim cellHasValue, backfilledData As Range
Dim backfillDate As Integer


For backfillDate = 3 To 122
    Set cellHasValue = Sheet24.Cells(backfillDate, 4) 'Sheet 24 - Rolling_window_data
    If IsNumeric(cellHasValue.Value) And Not IsEmpty(cellHasValue.Value) _
        And Not IsError(cellHasValue.Value) Then 'iterate through range D3:D122 to check for backfilled date
        With Sheet24
            Set backfilledData = .Range("B3", "B" & backfillDate)
            .Range("T3", "T" & backfillDate).Value = backfilledData
            .Range("B3", "B" & backfillDate - 1).ClearContents
        End With
        With Sheet49.ChartObjects("Chart 4").Activate 'Sheet 49 - Port Historical Risk
            With ActiveChart.SeriesCollection.NewSeries
                .Name = "=Rolling_window_data!$T$2"
                .Format.Line.DashStyle = msoLineDash
                .AxisGroup = xlSecondary
                .XValues = "=Rolling_window_data!$A$3:$A$122"
                .Values = "=Rolling_window_data!$T$3:$T$122"
            End With
        End With
        Exit For
    End If
Next backfillDate
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top