Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

colour coding bar graphs

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Colour coding bar of graphs

Colour coding bar of graphs

ResolvedVersion 2010

Rhian has attended:
Excel VBA Intro Intermediate course

Colour coding bar of graphs

how do you create a loop where each time a different bar on a graph is coloured differently

RE: colour coding bar of graphs

To be more specific the loop needs to look through a list of items and then on each sheet colour code the same bar on a graph throughout the worksheet.

RE: colour coding bar of graphs

Hi Rhian

Hope you are well. Here's a way to colour a column chart according to the type of item (in this case fruit).

Say the data looks like this -

Fruit Quantity sold
Pears 200
Oranges 120
Apples 70
Bananas 230
Blueberries 30

Here's the vba code. See if you can adapt it for your example. It assumes the chart already exists and called Chart1.

Dim PointNo As Integer
Dim NumItems As Integer
Dim Items(20) As String ' an array variable of 20 items

Dim n As Integer
n = 1

' count number of items

NumItems = Range("A1").CurrentRegion.Rows.Count - 1

'Add list of items to an array variable
For n = 1 To NumItems
Items(n) = Range("a2").Cells(n, 1).Value
Next n

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(1).Select

'select the colours one by one
For PointNo = 1 To NumItems

ActiveChart.FullSeriesCollection(1).Point(PointNo).Select
Select Case Items(PointNo)
Case Is = "Apples"
Selection.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
Case Is = "Pears"
Selection.Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
Case Is = "Oranges"
Selection.Format.Fill.ForeColor.RGB = RGB(255,192, 0)
Case Is = "Bananas"
Selection.Format.Fill.ForeColor.RGB = RGB(255, 255, 0)
Case is = "Blueberries"
Selection.Format.Fill.ForeColor.RGB = RGB(0, 0, 255)
Case Else
Selection.Format.Fill.ForeColor.RGB = RGB(255, 255, 255)

End Select

Next PointNo

Range("A1").Select
End Sub

Let me know how you get on!

Doug Dunn
Best STL


Will be marked as resolved in 5 days

Notice: This is an automated message. Due to inactivity, this forum post will be marked as 'resolved' if there are no further responses in the next 5 days.

RE: colour coding bar of graphs

Hello Rhian,

I am currently going through our forum to clear out any active questions. Can you please tell me whether you have managed to resolve this problem?

If not, please reply within five days so I can contact a trainer who can help you, otherwise this question will be marked as Resolved.

Thank you for your assistance.

Regards
Cindy

Sun 9 Jun 2013: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Creating a range of monthly payments as text

You could use a formula to create a range of payment ie. payment amount for x% to y% rate with fixed terms and principle.

The text that would be "between Xamount and Yamount".

Here is how to do it.

1 Use the PMT function to get your monthly payments figure or whatever frequency of payments that you choose he start range.

See PMT under Excel Help

2. Nest these in the ROUND function to round decimals see ROUND under Excel Help


3. Concatenate this using "&" and concatenate " to " and concatenate "Between ".

4. Concatenate the above to PMT function for the end range

ie.

="Between "&ROUND((PMT1),decimal places)&" and "&ROUND((PMT2),decimal places)

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.