Hi have a dynamic pie chart that runs off a drop down box in a spreadsheet.
I want to update the piechart once the dropdown selection has been made.
What code do I need to enter for this to happen? Where also do I need to put it?
Here's the code I have already...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("n5:n18")) Is Nothing Then
Select Case Target
Case "Green"
icolor = 4
Case "Red"
icolor = 3
Case Else
'Whatever
End Select
Target.Interior.ColorIndex = icolor
End If
End Sub
Sub ColorPieSlices()
' Copyright 1999 MrExcel.com
' This macro will re-color the pie slices in a chart
' So that slices for a specific category are similarly colored
' Select the chart before calling the macro
' Find the number of pie slices in this chart
NumPoints = ActiveChart.SeriesCollection(1).Points.Count
' Loop through each pie slice
For x = 1 To NumPoints
' Save the label currently attached to this slice
If ActiveChart.SeriesCollection(1). _
Points(x).HasDataLabel = True Then
SavePtLabel = ActiveChart.SeriesCollection(1) _
.Points(x).DataLabel.Text
Else
SavePtLabel = ""
End If
' Assign a new data label of just the point name
ActiveChart.SeriesCollection(1).Points(x).ApplyDataLabels Type:= _
xlDataLabelsShowLabel, AutoText:=True
ThisPt = ActiveChart.SeriesCollection(1).Points(x).DataLabel.Text
' Based on the label of this slice, set the color
Select Case ThisPt
Case "Canteen Costs"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m5").Value
Case "Carrier Bags"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m6").Value
Case "Cash Banking"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m7").Value
Case "Cost of Uniforms"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m8").Value
Case "Dishonoured Sales"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m9").Value
Case "Lottery Shorts"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m10").Value
Case "Packaging"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m11").Value
Case "Petty Cash Paid Out"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m12").Value
Case "Print, Post & Stationery"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m13").Value
Case "Refunds & Goodwill"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m14").Value
Case "Telephones"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m15").Value
Case "GSNFR"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m16").Value
Case "Green Points"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m17").Value
Case "Business Travel & Accommodation"
ActiveChart.SeriesCollection(1). _
Points(x).Interior.ColorIndex = Range("m18").Value
Case Else
' Add code here to handle an unexpected label
End Select
' Return the label to it's original pre-macro state
ActiveChart.SeriesCollection(1). _
Points(x).DataLabel.Text = SavePtLabel
Next x
End Sub
Hello ianththirlwell and welcome to the forum.
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
Please leave a message after the beep!
After you've fixed the code tags, please have a look at the link in my signature.
A pie chart with more than three slices is pretty much useless.
If you want your chart to convey useful information, then don't use a pie chart.
cheers,
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks