Format chart colours based on series values
up vote
2
down vote
favorite
Is it possible to format the colours of a bar chart with a single series based on their values, i.e. anything over 50 would be green, anything below would be red?
What I currently have to do is a workaround:
I have my data for the original series, and then I create 2 subsets. One for red, one for green,
and use an if statement to pull through only values above 50 for the green series, and below 50 for red series, then plot both the series, obviously where one has gaps, the other doesn't.
But this is annoying, I would much prefer for an easy way to set a conditional format on the actual series itself.
Is this possible?
microsoft-excel charts conditional-formatting
add a comment |
up vote
2
down vote
favorite
Is it possible to format the colours of a bar chart with a single series based on their values, i.e. anything over 50 would be green, anything below would be red?
What I currently have to do is a workaround:
I have my data for the original series, and then I create 2 subsets. One for red, one for green,
and use an if statement to pull through only values above 50 for the green series, and below 50 for red series, then plot both the series, obviously where one has gaps, the other doesn't.
But this is annoying, I would much prefer for an easy way to set a conditional format on the actual series itself.
Is this possible?
microsoft-excel charts conditional-formatting
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Is it possible to format the colours of a bar chart with a single series based on their values, i.e. anything over 50 would be green, anything below would be red?
What I currently have to do is a workaround:
I have my data for the original series, and then I create 2 subsets. One for red, one for green,
and use an if statement to pull through only values above 50 for the green series, and below 50 for red series, then plot both the series, obviously where one has gaps, the other doesn't.
But this is annoying, I would much prefer for an easy way to set a conditional format on the actual series itself.
Is this possible?
microsoft-excel charts conditional-formatting
Is it possible to format the colours of a bar chart with a single series based on their values, i.e. anything over 50 would be green, anything below would be red?
What I currently have to do is a workaround:
I have my data for the original series, and then I create 2 subsets. One for red, one for green,
and use an if statement to pull through only values above 50 for the green series, and below 50 for red series, then plot both the series, obviously where one has gaps, the other doesn't.
But this is annoying, I would much prefer for an easy way to set a conditional format on the actual series itself.
Is this possible?
microsoft-excel charts conditional-formatting
microsoft-excel charts conditional-formatting
edited Nov 7 at 17:13
DavidPostill♦
102k25220255
102k25220255
asked Nov 7 at 11:39
PeterH
3,32632246
3,32632246
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote

Enter following VBA code as Module:
Sub FormatChartbyColour()
Set rRng = Selection
ColorIndex1 = 3
ColorIndex2 = 4
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=rRng
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "=""Colour 1"""
ActiveChart.SeriesCollection(2).Name = "=""Colour 2"""
ActiveChart.SeriesCollection(3).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex1)
ActiveChart.SeriesCollection(2).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex2)
With ActiveChart.Parent
.Height = 250
.Width = 250
.Top = 100
.Left = 100
End With
ActiveChart.Axes(xlCategory).TickLabels.Font.Size = 10
ActiveChart.Axes(xlCategory).TickLabels.Font.Bold = False
ActiveChart.Axes(xlCategory).TickLabels.Font.Italic = True
ActiveChart.ChartTitle.Text = "Chaert Title (Colour1:Red , Colour2:Green)"
ActiveChart.ChartTitle.Font.Size = 10
With ActiveChart
vX = .SeriesCollection(1).XValues
vY = .SeriesCollection(1).Values
For thisvY = 1 To UBound(vY)
If vY(thisvY) = 1 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex1
If vY(thisvY) = 2 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex2
Next thisvY
End With
End Sub
How it works:
- Select Data Range
A23:C27. - RUN the Macro.
Note:
Col Index is Helper Column, you may alterColors.- Chart Type & Size are editable.
- Adjust cell references as you need.
Hey @Rajesh S, thanks for the answer, but having 2 series, one for each colour is what I already do as a work around. I was looking for a way to set two colours conditionally one a single series
– PeterH
Dec 3 at 8:09
@PeterH,, I think in that case you need Clustered Bar graph,, or if possible share Some sample data so I can try also. ☺
– Rajesh S
Dec 4 at 4:31
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote

Enter following VBA code as Module:
Sub FormatChartbyColour()
Set rRng = Selection
ColorIndex1 = 3
ColorIndex2 = 4
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=rRng
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "=""Colour 1"""
ActiveChart.SeriesCollection(2).Name = "=""Colour 2"""
ActiveChart.SeriesCollection(3).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex1)
ActiveChart.SeriesCollection(2).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex2)
With ActiveChart.Parent
.Height = 250
.Width = 250
.Top = 100
.Left = 100
End With
ActiveChart.Axes(xlCategory).TickLabels.Font.Size = 10
ActiveChart.Axes(xlCategory).TickLabels.Font.Bold = False
ActiveChart.Axes(xlCategory).TickLabels.Font.Italic = True
ActiveChart.ChartTitle.Text = "Chaert Title (Colour1:Red , Colour2:Green)"
ActiveChart.ChartTitle.Font.Size = 10
With ActiveChart
vX = .SeriesCollection(1).XValues
vY = .SeriesCollection(1).Values
For thisvY = 1 To UBound(vY)
If vY(thisvY) = 1 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex1
If vY(thisvY) = 2 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex2
Next thisvY
End With
End Sub
How it works:
- Select Data Range
A23:C27. - RUN the Macro.
Note:
Col Index is Helper Column, you may alterColors.- Chart Type & Size are editable.
- Adjust cell references as you need.
Hey @Rajesh S, thanks for the answer, but having 2 series, one for each colour is what I already do as a work around. I was looking for a way to set two colours conditionally one a single series
– PeterH
Dec 3 at 8:09
@PeterH,, I think in that case you need Clustered Bar graph,, or if possible share Some sample data so I can try also. ☺
– Rajesh S
Dec 4 at 4:31
add a comment |
up vote
0
down vote

Enter following VBA code as Module:
Sub FormatChartbyColour()
Set rRng = Selection
ColorIndex1 = 3
ColorIndex2 = 4
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=rRng
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "=""Colour 1"""
ActiveChart.SeriesCollection(2).Name = "=""Colour 2"""
ActiveChart.SeriesCollection(3).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex1)
ActiveChart.SeriesCollection(2).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex2)
With ActiveChart.Parent
.Height = 250
.Width = 250
.Top = 100
.Left = 100
End With
ActiveChart.Axes(xlCategory).TickLabels.Font.Size = 10
ActiveChart.Axes(xlCategory).TickLabels.Font.Bold = False
ActiveChart.Axes(xlCategory).TickLabels.Font.Italic = True
ActiveChart.ChartTitle.Text = "Chaert Title (Colour1:Red , Colour2:Green)"
ActiveChart.ChartTitle.Font.Size = 10
With ActiveChart
vX = .SeriesCollection(1).XValues
vY = .SeriesCollection(1).Values
For thisvY = 1 To UBound(vY)
If vY(thisvY) = 1 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex1
If vY(thisvY) = 2 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex2
Next thisvY
End With
End Sub
How it works:
- Select Data Range
A23:C27. - RUN the Macro.
Note:
Col Index is Helper Column, you may alterColors.- Chart Type & Size are editable.
- Adjust cell references as you need.
Hey @Rajesh S, thanks for the answer, but having 2 series, one for each colour is what I already do as a work around. I was looking for a way to set two colours conditionally one a single series
– PeterH
Dec 3 at 8:09
@PeterH,, I think in that case you need Clustered Bar graph,, or if possible share Some sample data so I can try also. ☺
– Rajesh S
Dec 4 at 4:31
add a comment |
up vote
0
down vote
up vote
0
down vote

Enter following VBA code as Module:
Sub FormatChartbyColour()
Set rRng = Selection
ColorIndex1 = 3
ColorIndex2 = 4
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=rRng
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "=""Colour 1"""
ActiveChart.SeriesCollection(2).Name = "=""Colour 2"""
ActiveChart.SeriesCollection(3).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex1)
ActiveChart.SeriesCollection(2).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex2)
With ActiveChart.Parent
.Height = 250
.Width = 250
.Top = 100
.Left = 100
End With
ActiveChart.Axes(xlCategory).TickLabels.Font.Size = 10
ActiveChart.Axes(xlCategory).TickLabels.Font.Bold = False
ActiveChart.Axes(xlCategory).TickLabels.Font.Italic = True
ActiveChart.ChartTitle.Text = "Chaert Title (Colour1:Red , Colour2:Green)"
ActiveChart.ChartTitle.Font.Size = 10
With ActiveChart
vX = .SeriesCollection(1).XValues
vY = .SeriesCollection(1).Values
For thisvY = 1 To UBound(vY)
If vY(thisvY) = 1 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex1
If vY(thisvY) = 2 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex2
Next thisvY
End With
End Sub
How it works:
- Select Data Range
A23:C27. - RUN the Macro.
Note:
Col Index is Helper Column, you may alterColors.- Chart Type & Size are editable.
- Adjust cell references as you need.

Enter following VBA code as Module:
Sub FormatChartbyColour()
Set rRng = Selection
ColorIndex1 = 3
ColorIndex2 = 4
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=rRng
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "=""Colour 1"""
ActiveChart.SeriesCollection(2).Name = "=""Colour 2"""
ActiveChart.SeriesCollection(3).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex1)
ActiveChart.SeriesCollection(2).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(ColorIndex2)
With ActiveChart.Parent
.Height = 250
.Width = 250
.Top = 100
.Left = 100
End With
ActiveChart.Axes(xlCategory).TickLabels.Font.Size = 10
ActiveChart.Axes(xlCategory).TickLabels.Font.Bold = False
ActiveChart.Axes(xlCategory).TickLabels.Font.Italic = True
ActiveChart.ChartTitle.Text = "Chaert Title (Colour1:Red , Colour2:Green)"
ActiveChart.ChartTitle.Font.Size = 10
With ActiveChart
vX = .SeriesCollection(1).XValues
vY = .SeriesCollection(1).Values
For thisvY = 1 To UBound(vY)
If vY(thisvY) = 1 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex1
If vY(thisvY) = 2 Then .SeriesCollection(2).Points(thisvY).Interior.ColorIndex = ColorIndex2
Next thisvY
End With
End Sub
How it works:
- Select Data Range
A23:C27. - RUN the Macro.
Note:
Col Index is Helper Column, you may alterColors.- Chart Type & Size are editable.
- Adjust cell references as you need.
answered Dec 1 at 12:40
Rajesh S
3,5401422
3,5401422
Hey @Rajesh S, thanks for the answer, but having 2 series, one for each colour is what I already do as a work around. I was looking for a way to set two colours conditionally one a single series
– PeterH
Dec 3 at 8:09
@PeterH,, I think in that case you need Clustered Bar graph,, or if possible share Some sample data so I can try also. ☺
– Rajesh S
Dec 4 at 4:31
add a comment |
Hey @Rajesh S, thanks for the answer, but having 2 series, one for each colour is what I already do as a work around. I was looking for a way to set two colours conditionally one a single series
– PeterH
Dec 3 at 8:09
@PeterH,, I think in that case you need Clustered Bar graph,, or if possible share Some sample data so I can try also. ☺
– Rajesh S
Dec 4 at 4:31
Hey @Rajesh S, thanks for the answer, but having 2 series, one for each colour is what I already do as a work around. I was looking for a way to set two colours conditionally one a single series
– PeterH
Dec 3 at 8:09
Hey @Rajesh S, thanks for the answer, but having 2 series, one for each colour is what I already do as a work around. I was looking for a way to set two colours conditionally one a single series
– PeterH
Dec 3 at 8:09
@PeterH,, I think in that case you need Clustered Bar graph,, or if possible share Some sample data so I can try also. ☺
– Rajesh S
Dec 4 at 4:31
@PeterH,, I think in that case you need Clustered Bar graph,, or if possible share Some sample data so I can try also. ☺
– Rajesh S
Dec 4 at 4:31
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1373426%2fformat-chart-colours-based-on-series-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown