Results 1 to 6 of 6

Pie Chart - Conditional Formatting with VBA

Threaded View

clutch12 Pie Chart - Conditional... 04-24-2009, 02:41 PM
clutch12 Pie Chart - Conditional... 04-24-2009, 02:45 PM
Andy Pope Re: Pie Chart - Conditional... 04-25-2009, 07:17 AM
Andy Pope Re: Pie Chart - Conditional... 04-25-2009, 08:41 AM
somersetdream Re: Pie Chart - Conditional... 02-03-2010, 06:14 AM
Andy Pope Re: Pie Chart - Conditional... 02-03-2010, 06:19 AM
  1. #2
    Registered User
    Join Date
    04-23-2009
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2003
    Posts
    2

    Pie Chart - Conditional formatting with VBA

    I am trying to create a VBA macro to conditionally format a pie chart in which all slices are the same size but the slice color will vary (and a color can repeat slice to slice) based on an adjacent value being one of three options. In the example in the attached spreadsheet, Column provides the size of the slice and Column C provide the % completion the slice color of which should correspond to the legend in B11:B13. I have used Jon Peltier's VBA code (below) as extracted from this website (http://pubs.logicalexpressions.com/P...cle.asp?ID=390), but I don't know how to adjust the code to get the macro to pick up the % completion values and apply slice colors accordingly.

    Sub ColorByPercent()
    Dim iPtCt As Integer
    Dim iPtIx As Integer
    Dim iCell As Integer
    Dim dTotal As Double
    Dim rColor As Range
    Dim vVals As Variant

    dTotal = 0
    Set rColor = ActiveSheet.Range("B11:B13")
    If ActiveChart Is Nothing Then
    MsgBox "Select a chart and try again.", vbExclamation
    Else
    With ActiveChart.SeriesCollection(1)
    iPtCt = .Points.Count
    vVals = .Values
    For iPtIx = 1 To iPtCt
    dTotal = dTotal + vVals(iPtIx)
    Next
    For iPtIx = 1 To iPtCt
    iCell = WorksheetFunction.Match(vVals(iPtIx) _
    / dTotal, rColor, 1)
    .Points(iPtIx).Interior.ColorIndex = _
    rColor.Resize(1, 1).Offset(iCell - 1, 0) _
    .Interior.ColorIndex
    Next
    End With
    End If
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.6.0 RC 1