+ Reply to Thread
Results 1 to 6 of 6

VBA filter Pivot Table to only user selected value

  1. #1
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    VBA filter Pivot Table to only user selected value

    I am trying to use VBA to filter a pivot table. My problem is that I want to make sure the only thing showing is the one item the user selected. How do I make sure to turn off all of the other values?

    I have a range (CAList). When the user clicks on one of those cells, I want the "CA" field in the pivot table (PivotTable2) to be filtered to show the CA that the user clicked on. This is the code I have right now. I can see it cycling through and making all of the CA's invisible and then making the correct one visible, but the table on the sheet is always left with the last CA being visible.

    Please Login or Register  to view this content.

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

    Re: VBA filter Pivot Table to only user selected value

    Hi Nigel,

    That feature is built into Excel 2010 and newer. It is called the Slicer. Can you upgrade? See:
    http://www.addictivetips.com/microso...tables-charts/
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: VBA filter Pivot Table to only user selected value

    I like the slicer, but my other problem is that I need to be able to store that value to use in another cell on the spreadsheet. With the VBA I have I can see what value the user clicked and put it in a cell where I can use it for other calculations. If I can pull the value of the slicer out and put it in a cell then I would be happy to use the slicer.

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

    Re: VBA filter Pivot Table to only user selected value

    Before 2010 Excel came out, I wrote a lot of VBA code to do what you are working on. It doesn't work if there is no value in your data that you want to filter on. It took days of work to make it all work correctly. The Slicer tool was my answer but I didn't have it in 2009. I'd suggest an upgrade to get the feature you desire.

  5. #5
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: VBA filter Pivot Table to only user selected value

    I have office 2010 and I do like using the slicer for something like this. Do you know the vba code to pull out the value of what the user has selected with the slicer? I've looked through several websites and I am not able to understand the code well enough to see how to pull the value of the slicer and put it into a cell.

  6. #6
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: VBA filter Pivot Table to only user selected value

    I figured out a way to make this work. The problem with my original code is that a pivot table cannot be filtered to have nothing selected. Originally I was trying to clear the filter and then filter to only show the item the user had clicked. In the code below which works, I first filter to show everything, then I filter out each item except the one the user selected. Once I added in the code to stop the screen from showing the update process it looks great. This code does what I want but I would still be happy if someone let me know if this code could be improved.

    Please Login or Register  to view this content.

+ 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. Replies: 6
    Last Post: 07-31-2014, 12:56 PM
  2. Pivot table not showing the selected items when filter added
    By ShaliniGomes in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-23-2014, 01:44 AM
  3. User form to filter data from pivot table
    By kmprocto in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2012, 03:22 PM
  4. Counting the number of Selected Fields in a Pivot Table Filter
    By adoepker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-09-2011, 11:53 AM
  5. Pivot Table Filter by User Entry
    By Jayco in forum Excel General
    Replies: 1
    Last Post: 08-16-2006, 09:35 PM

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