+ Reply to Thread
Results 1 to 3 of 3

Thread: How do I get a chart to update automatically once a dropdown box selection is made

  1. #1
    Registered User
    Join Date
    09-21-2011
    Location
    Bridgend, Wales
    MS-Off Ver
    Excel 2003
    Posts
    1

    How do I get a chart to update automatically once a dropdown box selection is made

    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

  2. #2
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,274

    Re: How do I get a chart to update automatically once a dropdown box selection is mad

    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!

  3. #3
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,150

    Re: How do I get a chart to update automatically once a dropdown box selection is mad

    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,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0