+ Reply to Thread
Results 1 to 10 of 10

Updating PivotTable filters based on other cell value

  1. #1
    Registered User
    Join Date
    02-01-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    15

    Updating PivotTable filters based on other cell value

    Hi there guy/girls!

    Hope youre well.

    Im using the following bit of code to try and get the filter of a pivottable to change based on the text displayed in a cell on the data sheet.

    Please Login or Register  to view this content.
    This works great! The problem ive got is if say "Joe Blogs" has made no customer contacts and his name is in Data!B1 the script will error. However is "Mary Smith" has made contacts and her name is in Data!B1 in the script will run, change the value and move on.

    Can anyone think of a way to make the script just set the value as "(BLANK)" if the selected name is Data!B1 has made no contacts?

    your help is greatly appreciated! My hair is falling out!

    Cheers,
    Dale
    Last edited by romperstomper; 04-06-2011 at 03:42 AM. Reason: change quote to code tags

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

    Re: Updating PivotTable filters based on other cell value

    Hi Dale,

    I've run into this problem a few times and have a suggestion.

    PivotFields and PivotItems are indexed.. That means you can do code like
    Please Login or Register  to view this content.
    in the immediate window and it will return the name of the second PivotField
    Also the
    Please Login or Register  to view this content.
    will return the number of PivotFields.

    The big pictre is you loop through your Pivot Tables or Pivot Fields or Pivot Items from 1 to their Counts and do things.

    This is the big picture and has worked for me but I'd need a sample file and exactly what youi are attempting to get a real answer.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    02-01-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Updating PivotTable filters based on other cell value

    Thanks for your post.

    Im not quite sure i understand.

    to clarify - my problem is the marco above works, its linked to a button and when the macro is ran there is no problem unless a the name in the range that the macro is looking at in this case "Data!B1"

    To clarify - the marco above works with no problem unless the data in the range where the macro is looking - in this case "Data:B1" - does not exist in the filters for that pivot table.
    For everyone else is works a treat!

    The reason its important for it to skip over the error is there is a host of other commands that need to be ran after this including other pivot updates.

    Thanks again for your post & i look forward to hearing back!

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

    Re: Updating PivotTable filters based on other cell value

    Hi Dale,
    I guess I need a sample file with an example to help much more. I have filtered pivot items using code a few times but use the index number of the item to do it. I have not use the For Each loop and would need to see why it doesn't work for you. I also don't quite understand the a single cell filter name range and how this applies to the pivot items.

  5. #5
    Registered User
    Join Date
    02-01-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Updating PivotTable filters based on other cell value

    Quote Originally Posted by MarvinP View Post
    Hi Dale,
    I guess I need a sample file with an example to help much more. I have filtered pivot items using code a few times but use the index number of the item to do it. I have not use the For Each loop and would need to see why it doesn't work for you. I also don't quite understand the a single cell filter name range and how this applies to the pivot items.
    Thanks for your response.

    Ive attached a file. I hope this helps! This is still wrecking my brain and ive had all night to think about it!

    Cheers
    Attached Files Attached Files

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

    Re: Updating PivotTable filters based on other cell value

    Hi Dale,

    I'm on my way out the door but here is some code I think you'll want to study
    Please Login or Register  to view this content.
    The idea is it goes throught all the pivotitems and makes the item show.

    I was thinking you could use a similar loop to turn on all your pivot items.

    If this doesn't help, reply back and I'll look at your code tomorrow.

  7. #7
    Registered User
    Join Date
    02-01-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Updating PivotTable filters based on other cell value

    Quote Originally Posted by MarvinP View Post
    Hi Dale,

    I'm on my way out the door but here is some code I think you'll want to study
    Please Login or Register  to view this content.
    The idea is it goes throught all the pivotitems and makes the item show.

    I was thinking you could use a similar loop to turn on all your pivot items.

    If this doesn't help, reply back and I'll look at your code tomorrow.
    Hi Marvin,

    Thanks again!

    Ive looked over this however i dont think that will work. From what i understand - and keep in mind im clearly a novice compared to you - that just selects all the data and skips?

    I look forward to your thoughts on the file i uploaded. Youll see how i have got the macro and how it errors. I hope it will shine some light on the problem to you and clear all confusion.

    Cheers,
    Dale

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

    Re: Updating PivotTable filters based on other cell value

    Hi Dale,
    You can't unselect all filter items but try this code. It is a work-a-round where if the name isn't found then I set the LInked Name1 filter to not show anyone.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-26-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Updating PivotTable filters based on other cell value

    Hello I found this thread...
    I need a similar solution -
    I would like the pivot table filter to be based the on a selected cell - automatically. Is that possible?

  10. #10
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Updating PivotTable filters based on other cell value

    Hello YoExceller. Please read the following. Thanks.

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

+ 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