98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Colour coding bar of graphs
Colour coding bar of graphs
Resolved · Medium Priority · Version 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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:New to Excel 2010 - Sparklines!Excel 2010 includes a new feature called Sparklines which are tiny charts that fit into a single cell and plot data in cells from the worksheet. There are a host of formatting and styles that can be applied to them and they are really quite interesting. |