+ Reply to Thread
Results 1 to 3 of 3

Apply code in all pivot tables in the same worksheet

  1. #1
    Valued Forum Contributor
    Join Date
    02-07-2013
    Location
    Philippines
    MS-Off Ver
    Excel Online; 365
    Posts
    610

    Apply code in all pivot tables in the same worksheet

    Hi Experts,

    i found this code but I could not modify it so it would work on two pivot tables on the same sheet:

    Set TargetDate = Range("A1")
    Dim PI As PivotItem


    For Each PI In ActiveSheet.PivotTables("PivotTable1").PivotFields("Target Due Date").PivotItems
    If DateValue(PI.Name) < TargetDate Or DateValue(PI.Name) = TargetDate Then
    PI.Visible = True
    Else
    PI.Visible = False
    End If
    Next PI

    How do I get a code to work on at least two pivot tables on the same sheet?

    I apologize if i do not know how to use code tags.

    Thank you
    If I've helped U pls click on d *Add Reputation

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Apply code in all pivot tables in the same worksheet

    You're missing a thing or two. There are two ways to point to a lot of things in VB. One is by what I like to call "array" like Sheet(1) or Sheet("SheetName"). Normally you address these items like:
    Please Login or Register  to view this content.
    The other is by pointer or "object" which is what I will use here. These are addressed using For Each
    Please Login or Register  to view this content.
    This should work for your purposes.
    Please Login or Register  to view this content.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Apply code in all pivot tables in the same worksheet

    Hi,

    Try changing
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy worksheet and VBA code to only apply to new worksheet
    By tejay in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-04-2015, 09:45 PM
  2. [SOLVED] Pivot Tables - How do you apply a new colour to one of the preset styles
    By MissDB in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 10-06-2014, 12:40 PM
  3. Apply a procedure only to specific pivot tables (MDX)
    By nomad80 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-19-2014, 07:24 AM
  4. [SOLVED] VBA code to launch macro on another worksheet and generate pivot tables
    By greyscale in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-22-2012, 01:14 AM
  5. Replies: 0
    Last Post: 09-22-2012, 07:22 PM
  6. Replies: 1
    Last Post: 02-22-2012, 12:21 PM
  7. Replies: 1
    Last Post: 02-18-2005, 10:06 AM

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