Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Pie Charts in Excel

Status
Not open for further replies.

campbemr

Technical User
Aug 16, 2001
19
US
For some reason I could not search for any topics like this so I have to post it as a question.

I am trying to make a pie chart in excel. There are going to be five values for this pie chart. I need the pie chart to be able to compare each of these five values with another set value and then change the color of that section of the pie accordingly. If the value for the pie chart is less than the set value, I want that section to be green, if not it needs to be red. I don't know if this needs to be done as a macro or not. If it does need to be done as a macro, it would need to update itself automatically.

Any help or ideas would be appreciated. Maybe there is some way to us conditional statements in the chart wizard that someone knows about? I have started writing a macro for this but I wouldn't know how to automatically update it whenever the worksheet with the chart is viewed.
 
Also, I do not know how I would change the sections individually. Pretty much I don't know how to do this at all.
 
For starters, the events you could use are the sheet activate event or the worksheet change event. The former will run the macro whenever youmove to the sheet in question. The latter will run whenever a change is made to the sheet

In terms of figuring out the code, try recording yourself (Tools>Macros>Record Macro) changing the colours on the pie chart Rgds
~Geoff~
 
Okay, I haven't gotten to far on this. I want the chart name to be a value from on of the other worksheets. With the code below I get an error : Method 'Location' of object '_Chart' failed. What am I doing wrong?

Dim Chart_Name, Goal_Values, Actual_Values
Chart_Name = Worksheets("Signoff Sheet").Range("A1").Value
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=Chart_Name
With ActiveChart
.ChartType = xlPie
.SetSourceData Source:=Sheets("Signoff Sheet").Range("I7:I66"),_ PlotBy:=xlColumns
End With

 
Nevermind, I understand what I was doing wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top