Conditionally format data series based on value

Dear Experts:

A macro should change the formatting for some custom named charts on the active Worksheet as follows:

Data Series that start in 2015 should have a different fill (RGB 230, 185, 184)

All of these charts are bar charts with just one data series

Not all of the charts of the active worksheet have to be formatted this way, but charts with the name 'MyChart_1', 'MyBizChart' and 'ProChart' (and other ones the names of which I will be able to enter into the provided macro code)

conditionally-format-data-series.png
Help is much appreciated. Thank you very much in advance.

I have attached a sample file for your convenience.

Regards, Andreas
Conditionally-format-data-series.xls
Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
Their you go enclosed is your workbook for your reference..where i did what you are looking for but i did without macro..this is conditional formatting only by the way I'm arranging my data and this will do what you are looking for as i tweaked your graphs only...

Saurabh...
Conditionally-format-data-series.xls
0
Andreas HermleTeam leaderAuthor Commented:
Hi Saurab,

astonishingly nice workaround, thank you very much for it, but to be honest with you, I would favor a macro solution. Maybe you will be able to provide me even a macro code.

Andreas
0
Saurabh Singh TeotiaCommented:
Andreas,

Any particular reason you are looking to this only by code??

Saurabh...
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Andreas HermleTeam leaderAuthor Commented:
Actually no specific reason
0
Saurabh Singh TeotiaCommented:
The reason i asked this question is because if i provide a macro solution for this i will be reading the range only from which you are preparing the chart and then coloring the series value accordingly...

Let me know if you are fine with the same and will write a macro for you...
0
Andreas HermleTeam leaderAuthor Commented:
Hi Saurabh, great, this is ok, no problem, thank you very much in advance.

Regards, Andreas
0
Saurabh Singh TeotiaCommented:
I'm confused whether you want me to write a macro or you are good with current solution??
0
Andreas HermleTeam leaderAuthor Commented:
oh sorry that I confused you, yes I would be very glad if you could write a macro for me.

Regards, Andreas
0
Saurabh Singh TeotiaCommented:
Their you go..Use this code for your first chart...

Sub ColorByValue()
    Dim rng As Range, cell As Range
    Dim iPattern As Long

    Set rng = ActiveSheet.Range("C16:C27")
     iPattern = 1
    For Each cell In rng
       
        If Year(cell.Value) = 2015 Then

            ActiveSheet.ChartObjects("MyChart_1").Select
            With ActiveChart.SeriesCollection(1)
                .Points(iPattern).Format.Fill.ForeColor.RGB = RGB(230, 185, 183)
            End With

        End If
        iPattern = iPattern + 1
    Next cell

End Sub

Open in new window


And use this code for your second chart which is Mybizchart...

Sub ColorByValue2()
    Dim rng As Range, cell As Range
    Dim iPattern As Long

    Set rng = ActiveSheet.Range("C51:C62")
     iPattern = 1
    For Each cell In rng
       
        If Year(cell.Value) = 2015 Then

            ActiveSheet.ChartObjects("MyBizChart").Select
            With ActiveChart.SeriesCollection(1)
                .Points(iPattern).Format.Fill.ForeColor.RGB = RGB(230, 185, 183)
            End With

        End If
        iPattern = iPattern + 1
    Next cell

End Sub

Open in new window


Saurabh...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
Hi Saurabh,

great, works just fine, thank you very much for your professional job. I really appreciate it.

Regards, Andreas
0
Saurabh Singh TeotiaCommented:
Yw.. Glad to help.. :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.