+ Reply to Thread
Results 1 to 13 of 13

Select ∑ values in PivotTable VBA

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

    Select ∑ values in PivotTable VBA

    Hello!

    I have a pivot table that will vary with number of columns as well as rows. I need some code that will select all of the ∑ values in the pivot table. I do not want the row labels or the column labels selected. ONLY the ∑ values so that i can apply conditional formatting. Please help!

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

    Re: Select ∑ values in PivotTable VBA

    perhaps
    Please Login or Register  to view this content.
    but you shouldn't need to actually select it
    Josie

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

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

    Re: Select ∑ values in PivotTable VBA

    Awesome! Works like a charm.

    Thanks JP!

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

    Re: Select ∑ values in PivotTable VBA

    Hey JP,

    One thing I need to alter for this line of code. The reason I needed to select the sum of values in the pivot table is to apply conditional formatting. The code I have to do this is as follows:

    Please Login or Register  to view this content.
    One thing that I need to change, is this is selecting my "Grand Total" at the bottom of the pivot table. However, I do not want to Conditional Format this line. How can I Offset this? I tried changing the DataBodyRange select statement to:
    Please Login or Register  to view this content.
    This did work to not select the "Grand Total" row, but it just shifted the selected range up 1 which included the pivot table headers. I'd like to select the databody range minus the grand total row. Any advice?

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

    Re: Select ∑ values in PivotTable VBA

    Please Login or Register  to view this content.
    for instance

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

    Re: Select ∑ values in PivotTable VBA

    Hey JP,

    the code failed at this line:

    Please Login or Register  to view this content.

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

    Re: Select ∑ values in PivotTable VBA

    my bad-remove the word Selection

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

    Re: Select ∑ values in PivotTable VBA

    Taking the selection out the code executes all the way through. However, It is not applying the conditional formatting properly like the beginning code I provided.

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

    Re: Select ∑ values in PivotTable VBA

    shoot-didn't see you were using relative addressing so you have to select
    Please Login or Register  to view this content.

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

    Re: Select ∑ values in PivotTable VBA

    JP,

    This works well for a few of my PivotTables. I am trying to apply this code to multiple tables. However, there are two formats of the pivottables in regards to what is in the Row Labels. The first code I have below (ConditionalFormatPT) is for a pivot table that only has "1 row label", hence why the formula "=LEN(TRIM(B10))=0" has B10 as the starting reference. In the second code I have below (ConditionalFormatPT2) is for a pivot table that has "2 row labels", hence why I have to push out the formula by one column since the 2nd row label is in column B and the DataBodyRange starts in C10. The ConditionalFormatPT works perfectly and applys the conditional formatting. However, for some strange reason, ConditonalFormatPT2 does not apply the conditional formatting whatsoever. After running the code, I go into the conditional formatting manage rules and there is not even a rule applied to the pivot table. Any idea as to why ConditionalFormatPT2 procedure is running all the way through but not applying the rule?

    Please Login or Register  to view this content.

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

    Re: Select ∑ values in PivotTable VBA

    I can't see anything obvious-perhaps you could attach a sample workbook?

    note: I am snowed at work at the moment so will not be around much for the next week or so

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

    Re: Select ∑ values in PivotTable VBA

    Unfortunately, I can't upload the workbook as it holds proprietary data. I am calling the ConditionalFormatPT2 procedure. The weird thing is, is that after calling the ConditionalFormatPT2, it doesn't apply the conditional formatting rule. But after the call statement and the VBA is done runnning, I go into the ConditionalFormatPT2 procedure and run this code individually, it applies the formatting rule. I am at a loss!!

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

    Re: Select ∑ values in PivotTable VBA

    Hey JP,

    Pretty weird, but all I did was moved the call statement and it worked. CHEERS! Thanks for all the help!

+ 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