+ Reply to Thread
Results 1 to 6 of 6

Display data labels on stacked bar pivot chart ONLY for values greater than 0

  1. #1
    Registered User
    Join Date
    01-19-2009
    Location
    Mexico
    MS-Off Ver
    Excel 2003
    Posts
    6

    Display data labels on stacked bar pivot chart ONLY for values greater than 0

    Hi, guys,

    Would you please help?

    I have a stacked bar pivot chart, which only displays the values greater than 0, but I don't want any labels from values equal to 0 showing up and making the chart basically unreadable. I just need the labels from values greater than 0, but getting them automatically with VBA code (macro).

    The way I´m doing this is referencing the seriescollection "points" which need to have labels applied. In another worksheet ("referencia") I basically copy the information from the pivot table from all 31 data fiels. Then, range D3:D33 contains the data field number if the value is greater than 0.

    Here's my code:

    Please Login or Register  to view this content.
    When I run this, I get runtime error '1004': Method 'SeriesCollection' of object '_Chart' failed. I think it has to do with my using the s variable on:
    Please Login or Register  to view this content.
    , since when I change it to a number, it works fine.

    I hope I made sense, but it's late here and I'm desperate.

    Thank you,
    José

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,435
    How about using a custom number format for the data labels?

    General;;
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    01-19-2009
    Location
    Mexico
    MS-Off Ver
    Excel 2003
    Posts
    6
    What do you mean?

    Thank you,
    José

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,435
    I missed in your code that your data label is actually displaying both Value and Series Name, in which case the custom number format will not work.

    What is the variable s referring to in your code?

  5. #5
    Registered User
    Join Date
    01-19-2009
    Location
    Mexico
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Display data labels on stacked bar pivot chart ONLY for values greater than 0

    Hi,

    The variable "s" is for the series point I need the label for.

    See, I have 31 columns on the pivot table, each of which have different values. All of these columns are in the pivot chart, but most have values equal to 0, so they're not displayed. I want to be able to automatically display labels for only all column values greater than 0.

    What I've done is reference the values in the pivot table on other cells, and if the value is greater than 0, the code has "s" equal to it, so that the "activechart.seriescollection(s).applydatalabels" can work.

    Thank you,
    José

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,435

    Thumbs up Re: Display data labels on stacked bar pivot chart ONLY for values greater than 0

    Does the range D3:D33 contain zero or the Index number of the series?
    If not, if the range contains actual data values then I guess it will fail when the value exceeds the number of series.
    Instead of reading the value of s from the range just use a counter

    Also the labels will be applied to the whole series, which may contain points with a zero value.
    Please Login or Register  to view this content.
    If still not working can you post small example file.

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