+ Reply to Thread
Results 1 to 9 of 9

Using VBA to select a few items in the Filter

  1. #1
    Registered User
    Join Date
    02-03-2012
    Location
    Portsmouth, UK
    MS-Off Ver
    office365
    Posts
    4

    Using VBA to select a few items in the Filter

    Hi, I am trying to use VBA to only select 6 items from a filter in a Pivot table. The number of items in the filter increases weekly but I still only want to select a set number. Below is part of the code that was produced when I used Macro recorder
    Sub Macro8()
    '
    ' Macro8 Macro
    '

    '
    ActiveSheet.PivotTables("PivotTable2").PivotFields("Work Pack Code"). _
    CurrentPage = "(All)"
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Work Pack Code")
    .PivotItems("0").Visible = False
    .PivotItems("4").Visible = False
    .PivotItems("30").Visible = False
    .PivotItems("40").Visible = False
    .PivotItems("105").Visible = False
    .PivotItems("130").Visible = False
    .PivotItems("133").Visible = False
    .PivotItems("142").Visible = False
    .PivotItems("200").Visible = False
    .PivotItems("202").Visible = False
    .PivotItems("210").Visible = False
    .PivotItems("300").Visible = False
    The list will increase each week with new data

    I only want to show 9002 , 9003,9004 , 9005

    Any help will be greatly appreciated.

    Thanks,

    Clyde
    Last edited by CLYDE2004; 11-27-2012 at 11:39 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Using VBA to select a few items in the Filter

    Might be an idea to post a sample workbook with some typical data ... specifically, an example of data that demonstrates the requirement above.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-03-2012
    Location
    Portsmouth, UK
    MS-Off Ver
    office365
    Posts
    4

    Re: Using VBA to select a few items in the Filter

    Hi, How do post sample workbook to this thread . Thanks for your help

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Using VBA to select a few items in the Filter

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  5. #5
    Registered User
    Join Date
    02-03-2012
    Location
    Portsmouth, UK
    MS-Off Ver
    office365
    Posts
    4

    Re: Using VBA to select a few items in the Filter

    Attached is a sample file. Column H - Work Pack Code is the column that I wish to filter but only want to select 9002,9003,9004 . The work pack codes will increase ech week and new ones are added but I still only want to select a few. Thanks for your help
    Attached Files Attached Files

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Using VBA to select a few items in the Filter

    OK, it's going to look something like this:

    Please Login or Register  to view this content.


    Regards, TMS

  7. #7
    Registered User
    Join Date
    02-03-2012
    Location
    Portsmouth, UK
    MS-Off Ver
    office365
    Posts
    4

    Re: Using VBA to select a few items in the Filter

    Hi, Thank you so much. That does the business. Thank you .

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Using VBA to select a few items in the Filter

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Using VBA to select a few items in the Filter

    Alternative version:

    Please Login or Register  to view this content.


    Please remember to mark as solved.


    Regards, TMS

+ 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