PC Review


Reply
Thread Tools Rate Thread

Delete any Lables with "0%" value in pie chart

 
 
MikeZz
Guest
Posts: n/a
 
      5th Aug 2008
Hi,
I have a macro that automatically applies formatted data labels to a pie
chart.
Data labels include Value, % of the Pie and the Legend Color.

The Chart Sheet is not a pivot chart but the data series points to a range
that contains data from a pivot table. I do it this way because Pivot Charts
seem to have limited formating and other options.

Because of how I point to the data range, it doesn't update the range if the
pivot table cells get smaller when applying filters.

This causes some "Zero" values in the data series if the pivot table gets
smaller.
This works fine for me in the pie chart since the value is Zero.

My question is:
How do I search through all the data points in the pie chart series, find
any datapoints where the data value = 0 and remove the data label from that
data point. Something like For Each Datapoint in ActiveChart..... is what
I"m thinking, I just can't figure out the syntax.

Here's the recorded macro where I just clicked on the various labels and
deleted them.

Sub Macro4()
Dim thisChart As Chart

Set thisChart = ActiveChart

thisChart.SeriesCollection(1).DataLabels.Select
thisChart.SeriesCollection(1).Points(12).DataLabel.Select
Selection.Delete
thisChart.SeriesCollection(1).DataLabels.Select
thisChart.SeriesCollection(1).Points(14).DataLabel.Select
Selection.Delete
thisChart.SeriesCollection(1).DataLabels.Select
thisChart.SeriesCollection(1).Points(13).DataLabel.Select
Selection.Delete
End Sub

Thanks,
MikeZz

 
Reply With Quote
 
 
 
 
Wigi
Guest
Posts: n/a
 
      5th Aug 2008
From a quick Google search action:

http://www.ozgrid.com/forum/showthread.php?t=89364


--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"MikeZz" wrote:

> Hi,
> I have a macro that automatically applies formatted data labels to a pie
> chart.
> Data labels include Value, % of the Pie and the Legend Color.
>
> The Chart Sheet is not a pivot chart but the data series points to a range
> that contains data from a pivot table. I do it this way because Pivot Charts
> seem to have limited formating and other options.
>
> Because of how I point to the data range, it doesn't update the range if the
> pivot table cells get smaller when applying filters.
>
> This causes some "Zero" values in the data series if the pivot table gets
> smaller.
> This works fine for me in the pie chart since the value is Zero.
>
> My question is:
> How do I search through all the data points in the pie chart series, find
> any datapoints where the data value = 0 and remove the data label from that
> data point. Something like For Each Datapoint in ActiveChart..... is what
> I"m thinking, I just can't figure out the syntax.
>
> Here's the recorded macro where I just clicked on the various labels and
> deleted them.
>
> Sub Macro4()
> Dim thisChart As Chart
>
> Set thisChart = ActiveChart
>
> thisChart.SeriesCollection(1).DataLabels.Select
> thisChart.SeriesCollection(1).Points(12).DataLabel.Select
> Selection.Delete
> thisChart.SeriesCollection(1).DataLabels.Select
> thisChart.SeriesCollection(1).Points(14).DataLabel.Select
> Selection.Delete
> thisChart.SeriesCollection(1).DataLabels.Select
> thisChart.SeriesCollection(1).Points(13).DataLabel.Select
> Selection.Delete
> End Sub
>
> Thanks,
> MikeZz
>

 
Reply With Quote
 
MikeZz
Guest
Posts: n/a
 
      5th Aug 2008
Thanks Wigi, you made it look so easy if I just put in the right words to
search!

An addition to this one is how do I check each Data Label and if it = a
certain value, make that pie slice a certain color? I want to have this so
that I can "syncronize" the colors of various changing charts so that the all
match.

Make the "Car" slice = Green
"House" slice = Red
"Utilities" slice = Blue
(regardless of the order in which they appear in the data series)


For instance if my pie data looks like this
Label Data
Car 1000
House 1500
Utilities 300


"Wigi" wrote:

> From a quick Google search action:
>
> http://www.ozgrid.com/forum/showthread.php?t=89364
>
>
> --
> Wigi
> http://www.wimgielis.be = Excel/VBA, soccer and music
>
>
> "MikeZz" wrote:
>
> > Hi,
> > I have a macro that automatically applies formatted data labels to a pie
> > chart.
> > Data labels include Value, % of the Pie and the Legend Color.
> >
> > The Chart Sheet is not a pivot chart but the data series points to a range
> > that contains data from a pivot table. I do it this way because Pivot Charts
> > seem to have limited formating and other options.
> >
> > Because of how I point to the data range, it doesn't update the range if the
> > pivot table cells get smaller when applying filters.
> >
> > This causes some "Zero" values in the data series if the pivot table gets
> > smaller.
> > This works fine for me in the pie chart since the value is Zero.
> >
> > My question is:
> > How do I search through all the data points in the pie chart series, find
> > any datapoints where the data value = 0 and remove the data label from that
> > data point. Something like For Each Datapoint in ActiveChart..... is what
> > I"m thinking, I just can't figure out the syntax.
> >
> > Here's the recorded macro where I just clicked on the various labels and
> > deleted them.
> >
> > Sub Macro4()
> > Dim thisChart As Chart
> >
> > Set thisChart = ActiveChart
> >
> > thisChart.SeriesCollection(1).DataLabels.Select
> > thisChart.SeriesCollection(1).Points(12).DataLabel.Select
> > Selection.Delete
> > thisChart.SeriesCollection(1).DataLabels.Select
> > thisChart.SeriesCollection(1).Points(14).DataLabel.Select
> > Selection.Delete
> > thisChart.SeriesCollection(1).DataLabels.Select
> > thisChart.SeriesCollection(1).Points(13).DataLabel.Select
> > Selection.Delete
> > End Sub
> >
> > Thanks,
> > MikeZz
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why do i "sometimes" need to "edit chart object" before "source da Flirty and Blonde Microsoft Excel Charting 1 2nd Feb 2010 02:07 PM
How can I add the icons "Delete", "Cut", "Copy" and "Paste" in Vis =?Utf-8?B?TW9vbndhbGtlcg==?= Windows Vista File Management 4 17th Sep 2007 11:02 PM
How to to prevent "shortcut to" lables beinmg attached? Don J Windows XP General 3 28th Jun 2007 12:50 PM
microsoft word, "lables" prints four not a full sheet, why? =?Utf-8?B?Q2FtcGVy?= Microsoft Word Document Management 1 6th Nov 2004 10:54 PM
Each time user clicks on "chart" a "chart tool box" appears.. can I disable? Kenji Microsoft Excel Worksheet Functions 0 29th Dec 2003 08:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:56 PM.