+ Reply to Thread
Results 1 to 11 of 11

PivotItems in a PivotTable position -- Skip if PivotItem errors

  1. #1
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    PivotItems in a PivotTable position -- Skip if PivotItem errors

    Hello!

    I have a pivot table which I have automated from a data set. There is only one field in the “row labels” and one field in the “∑ values” field. The following code works perfectly every time. However, I need to make the code dynamic in case there is an instance where one of the PivotItems isn’t contained in the data set. For instance, if there is no “BD2” in the dataset, then the following code will error out. What I need is if the code errors out since there is not a “PivotItem” contained in the dataset, then skip that line of code and continue to the next. This would be a HUGE help! Thank you so much!

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    Can anyone provide any insight into this?

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    can you change the first 9 items to use 2 digits-eg BD01? then you won't need code at all
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    Hey JP,

    Actually, there is a formula I am using to calculate the BD#. BD = Business Day. The maximum number of business days is 23. Sometimes, the business days won't be in the data set. It could include BD1, BD8, BD15, BD23. It will always be completely random as well as out of order. I would like to use code for this procedure. But only want to use error handling for this specific task.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    my point is that if you format them all with 2 digits they will sort the way you want automatically because that's alphabetical order

  6. #6
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    Ah, I see what you're saying. Yeah I can do a copy pastespecial values to eliminate the formula, then add a loop and replace the BD1-BD9 to include a 0 before this. I'll let you know if this indeed works.

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    what's the formula? you ought to be able to alter that to use two digits using the TEXT function

  8. #8
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    This is the following formula that is calculating the "Business Day" taking into account the following date format:

    MM/DD/YYYY:
    10/5/2012
    9/18/2012
    8/16/2012


    =IF(WEEKDAY(TRIM(B2),2)>5,"WEEKEND","BD" & NETWORKDAYS(EOMONTH(TRIM(B2),-1)+1,TRIM(B2)))


    I did just add some code that does the following:

    Please Login or Register  to view this content.
    The code works well, but if I can include a text section within the formula to eliminate this piece of code -- that would be CRUCIAL!!

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    =IF(WEEKDAY(TRIM(B2),2)>5,"WEEKEND","BD" & TEXT(NETWORKDAYS(EOMONTH(TRIM(B2),-1)+1,TRIM(B2)),"00"))
    oughta work

  10. #10
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    Works PERFECTLY JP! Thanks! I can now take out that whole loop procedure from the code out. AWESOME.

    Reputation points well deserved

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: PivotItems in a PivotTable position -- Skip if PivotItem errors

    you're welcome

    I love to code as much as the next guy-maybe more-but sometimes there are better ways ;-)

+ Reply to Thread

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