If I use VBA in Excel to make a line chart with multiple series, and two of the series' data are very similar so that their chart series lines partly overlap, the last one written is in front of earlier ones written.
In the Worksheet_Change
event, I want to be able to go back and forth between which chart series line is in front, based on user actions that change the data. Can I do that without deleting and recreating the chart?
Here's how I'm identifiying the series line, for example here's series 2:
Sheet1.ChartObjects("MyChart").Chart.SeriesCollection(2)
Getting TypeName
on that returns Series
. I see Series
in help, but with no information on its properties and methods. I don't see Series
in the Object Browser (I'm on Excel 2007). I was able to get a list of properties and methods in the context help dropdown, but I didn't see anything promising in the dropdown.
So, can I bring a chart series to the front/send it to the back, without deleting and recreating the chart?
Here is a simple non-VBA way to highlight one series in a chart.
Below I show X data in column B, Y data for series alpha, beta, and gamma in columns C:E, and extra data in column F.
I have a chart, and below the chart a combo box inserted using Developer tab > Insert > Form Controls > Combo Box. I formatted the control (right click) and set the Input Range to K16:18, and the Cell Link to J16.
I selected F2:F16, with F2 being the active cell. I entered =INDEX(C2:E2,$J$16)
in the formula bar, then held Ctrl while I pressed the Enter key. This filled the formula into the entire range. Essentially the formula takes the value from the three cells to the left, based on the Cell Link of the combo box. Since I've selected "beta" in the combo, J16 contains the value 2, and column F shows the values of the second data column.
The chart was made using the entire data range. The first three series were formatted with light gray lines, and the fourth (duplicate) series was formatted with a color that stands out in comparison. All data is visible at once, but only one is highlighted.