+ Reply to Thread
Results 1 to 8 of 8

Using VBA to update pivot table filter from multiple values in a list

  1. #1
    Registered User
    Join Date
    04-04-2018
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    5

    Exclamation Using VBA to update pivot table filter from multiple values in a list

    I am looking to create a VBA macro that has the ability to update one pivot table filter based on multiple cell values. I have successfully been able to create VBA code to update the pivot table filter with ONE value but would like to modify this code to update the filter with MULTIPLE values.

    Below is the code where I have successfully been able to update with ONE value:

    Please Login or Register  to view this content.
    My range of values that I would like to pull from is on Worksheet("INVOICE"), Range(S1:S15). Although this range goes down 15 rows, not all rows may have a value (case by case basis depending on invoice).

    I am pretty new to writing VBA code but am looking for any help to find a solution.

    Thank you,
    Tyler
    Last edited by tyler0320; 04-05-2018 at 04:19 PM. Reason: Code tag insert

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

    Re: Using VBA to update pivot table filter from multiple values in a list

    Two things:

    1. I am surprised that a moderator hasn't jumped in and told you to use code tags. Normally give first timers a "pass" and do it for them. Since I am not a moderator, I can't do it for you.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    2. Attach a sample file
    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    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
    Registered User
    Join Date
    04-04-2018
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Using VBA to update pivot table filter from multiple values in a list

    Thank you dflak for this information. I have followed the instructions for Rule 3 and have inserted the code tags.

    For some reason, I am receiving error message "upload of file failed" when attempting to attach the .xlsm doc through manage attachements..
    Last edited by tyler0320; 04-05-2018 at 05:32 PM.

  4. #4
    Registered User
    Join Date
    04-04-2018
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Using VBA to update pivot table filter from multiple values in a list

    I just realized my xlsm. is 2,124 kb in size and the max upload size for xlsm. is 1,000kb. Are there any other ways I can attach my doc?

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

    Re: Using VBA to update pivot table filter from multiple values in a list

    In theory, you should be stripping down your data to just enough to prove the point.

    I suggest two things. Resave the file as XLSB. XLSB files are smaller by about 40%. So that still might not get there.

    Second best is to compress the file and attach the ZIP file.

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Using VBA to update pivot table filter from multiple values in a list

    Key factor in PivotTable filtering is how your PivotTable is constructed.

    1. From regular Excel Table/Range
    This one requires loop through entire item list within field and .Visible property should be set for each one.
    As well, each status change will cause pivot table to refresh. To avoid slowdown of process, you should set .ManualUpdate to true at start of loop, and
    set it to false at end.

    Sample code:
    Please Login or Register  to view this content.
    2. OLAP data model based Pivot Table.
    I'd strongly recommend this approach. Since you have Office 365. Use PowerQuery to load data to data model and create pivot table from it.
    You can then use SlicerCache's .VisibleItemsList and use array to select multiple items at once. See link for where I did this in another forum.

    https://chandoo.org/forum/threads/ch...4/#post-224163
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  7. #7
    Registered User
    Join Date
    04-04-2018
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Using VBA to update pivot table filter from multiple values in a list

    Thank you CK76! I was successfully able to implement the OLAP data model code last night and it worked very well. But, this morning we are running across a VBA error "An issue with the Data Model is preventing Microsoft Excel from opening this workbook. Try restarting Microsoft Excel."

    Restarting Microsoft Excel does not resolve this issue & when pressing Debug, this code is highlighted:
    Please Login or Register  to view this content.
    Our invoice file that runs this code is stored on a team Sharepoint & is accessed by multiple computers. Could that cause this issue?

  8. #8
    Registered User
    Join Date
    04-04-2018
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Using VBA to update pivot table filter from multiple values in a list

    I believe I have fixed the issue above. In our invoicing workflow, we have a macro that clears invoicing contents, increases invoice number by 1, then resaves back over the invoicing template. This macro, for some reason, prevented the data model from saving. I was able to resolve this by editing that macro to only using the workbook with the saved data model.

    Thank you all for your assistance with this. Marking this thread as resolved

+ 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: 1
    Last Post: 02-25-2018, 09:47 PM
  2. Two pivot tables with the filter of pivot table 2 to automatically update to filter 1
    By StefaniaLa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2018, 06:19 PM
  3. How-to Copy and Paste Values from list into Pivot Table filter
    By MacroNerd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-05-2013, 06:26 PM
  4. [SOLVED] Use A Custom List of Values To Filter Pivot Table
    By dollylectric in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 09-29-2013, 01:05 PM
  5. Filter A Pivot Table Multiple Times Based On Values In List In Another Sheet
    By w.m.christensen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-24-2013, 03:55 AM
  6. i cannot filter the values from drop down list from a pivot table report
    By mamun_08023 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 08-21-2012, 02:50 PM
  7. filter pivot table with multiple values?
    By hamsup1o in forum Excel General
    Replies: 0
    Last Post: 09-29-2009, 04:08 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