Forum Discussion
Chart graphs that automatically change depending on the subject
- May 27, 2025
Have you tried the demo workbook that I attached to my previous reply? It should do exactly what you want.
This would be (relatively) easy if the 4 types were the series, and the scores for a type the series values.
The problem here (if I understand it correctly!) is that the series of the chart are the family members, so the number of series varies. In the example, the series for brother1 and brother4 should be removed.
The number of data points for each series is fixed: the scores for each of the 4 types.
We can solve it by creating a Worksheet_Change event procedure:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
If Not Intersect(Range("B2:K5"), Target) Is Nothing Then
Application.ScreenUpdating = False
With Me.ChartObjects(1).Chart
' Delete the existing series
For i = .SeriesCollection.Count To 1 Step -1
.SeriesCollection(i).Delete
Next i
' Add series for non-blank columns
For i = 2 To 11
If Cells(2, i).Value <> "" Then
.SeriesCollection.Add _
Source:=Cells(1, i).Resize(5), _
SeriesLabels:=True
End If
Next i
' We must specify the category labels again
.FullSeriesCollection(1).XValues = Range("A2:A5")
End With
Application.ScreenUpdating = True
End If
End Sub
See the attached demo workbook (I hope it will not be removed by the forum software).
Thank you for your reply.
I have a few more questions.
The maximum number of family members is 10,
and only the members with scores should be shown.
Just as brother1 and brother4 were not on the score sheet, there may or may not be scores in the middle.
That is, only members with scores should be
shown on the graph and reflected flexibly in the legend format.
In the case of brother1 and brother4, since they did not have scores,
they were omitted from the graph and legend format,
but they should be added to the graph and legend format again when they have scores.
And if one of the middle siblings is missing, the graph will also disappear, and the spacing should be adjusted automatically.
According to what you said,
the target is not added, the legend format is not automatically reflected, and when there is no score, the graph becomes blank.
I am very grateful for your kindness.
- HansVogelaarMay 27, 2025MVP
Have you tried the demo workbook that I attached to my previous reply? It should do exactly what you want.