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?










share|improve this question




























    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?










    share|improve this question


























      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 17:13









      DavidPostill

      102k25220255




      102k25220255










      asked Nov 7 at 11:39









      PeterH

      3,32632246




      3,32632246






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          enter image description here



          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 alter Colors.

          • Chart Type & Size are editable.

          • Adjust cell references as you need.






          share|improve this answer





















          • 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











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          enter image description here



          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 alter Colors.

          • Chart Type & Size are editable.

          • Adjust cell references as you need.






          share|improve this answer





















          • 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















          up vote
          0
          down vote













          enter image description here



          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 alter Colors.

          • Chart Type & Size are editable.

          • Adjust cell references as you need.






          share|improve this answer





















          • 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













          up vote
          0
          down vote










          up vote
          0
          down vote









          enter image description here



          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 alter Colors.

          • Chart Type & Size are editable.

          • Adjust cell references as you need.






          share|improve this answer












          enter image description here



          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 alter Colors.

          • Chart Type & Size are editable.

          • Adjust cell references as you need.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Mouse cursor on multiple screens with different PPI

          Agildo Ribeiro

          Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”