How to keep specific bar color in chart when the bar change position in chart (conditional bar color)

Manojlo

New Member
Joined
Sep 4, 2020
Messages
42
Office Version
  1. 365
Platform
  1. Windows
Hello

Is there any options to add specific color for single bar in chart, and bar to keep this color when change position in chart.
problem.jpg

For Example if we have two columns A i B, in A column (from A2:A5) we have words: Red, Blue, White, Yellow and Green, and in B column we have some values: 10, 20, 30, 40 and 50.
We make Clustered column chart in descending order, for example Green cell is on first place and have value 50, and I want to make this bar in green color even if I change values, for example 10 and it is not on first place anymore
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hello,

can be done with code

VBA Code:
Sub COLOUR_GRAPH()
    ActiveSheet.ChartObjects("Chart 1").Activate
    For MY_ROWS = 2 To 6
        ActiveChart.SeriesCollection(1).Points(MY_ROWS - 1).Select
            With Selection.Interior
                Select Case Range("A" & MY_ROWS).Value
                    Case "Red"
                        MY_COLOUR = 3
                    Case "Yellow"
                        MY_COLOUR = 6
                    Case "White"
                        MY_COLOUR = 2
                    Case "Blue"
                        MY_COLOUR = 5
                    Case "Green"
                        MY_COLOUR = 10
                End Select
        .ColorIndex = MY_COLOUR
        .Pattern = xlSolid
            End With
    Next MY_ROWS
End Sub

could be added to a worksheet change event.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,488
Members
448,967
Latest member
visheshkotha

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