• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Pivot Table Auto Filter base on Cell Value|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Pivot Table Auto Filter base on Cell Value|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosPivot Table Auto Filter base on Cel…
sp_PrintTopic sp_TopicIcon
Pivot Table Auto Filter base on Cell Value
Avatar
Mark Milan
Member
Members
Level 0
Forum Posts: 29
Member Since:
March 17, 2020
sp_UserOfflineSmall Offline
1
August 20, 2023 - 11:56 pm
sp_Permalink sp_Print sp_EditHistory

Hello,

 

I created a dashboard consisting of multiple pivot tables and slicers in a single sheet.

Then I inserted a VBA to filter pivot tables based on a cells value (top items; top percentage; bottom items; bottom percentage).

Now, I need to add 2 features, if it's possible:

1) I'd like to specify which is (or are) the pivot table (s) that I want to update, through a dropdown menu list.....

So, the selected pivot table (or tables) will update accordingly to the data filter typed (top item, top %, bottom items, bottom %). 

2) Now, the untyped pivot tables should update on the base of the filtered data of typed pivot tables

e.g.

Open the attachment and go to "Sheet2". Then, type Top % 10: you will see all the pivot tables will update accordingly. 

Now, I guess I want to update only "PivotTable2" (this is additional feature #1) 

After that,  I want also all the other PivotTables will update data based on filtered data in "PivotTable2" (this is additional feature #2) 

 

Any ideas? 

Please see attachment

regards

Mark

 

VBA CODE:

 

Option Explicit
'===================================
'MULTI PIVOT VERSION
Private Sub Worksheet_Change _
(ByVal Target As Range)
Dim ws As Worksheet
Dim wsL As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pfD As PivotField
Dim rngType As Range
Dim rngTypeSel As Range
Dim rngNum As Range
Dim lType As Long

On Error GoTo errHandler

Set ws = ActiveSheet
Set wsL = Worksheets("Sheet1")
Set rngType = ws.Range("TypeSel")
Set rngTypeSel _
= wsL.Range("TypeValSel")
Set rngNum = ws.Range("NumSel")

Select Case Target.Address
Case rngType.Address, _
rngNum.Address
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each pt In ws.PivotTables
Set pf = pt.RowFields(1)
Set pfD = pt.DataFields(1)
pf.ClearAllFilters
If rngNum.Value > 0 And _
rngTypeSel > 0 Then
pf.PivotFilters.Add _
Type:=rngTypeSel.Value, _
DataField:=pfD, _
Value1:=rngNum.Value
End If
Next pt

End Select

exitHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub

errHandler:
MsgBox "Could not apply filter"
Resume exitHandler
End Sub

'===================================
'SINGLE PIVOT VERSION
'---To use this version, comment out
'----MULTI PIVOT VERSION or delete it
'---Then, uncomment this procedure
'----------
'Private Sub Worksheet_Change _
'() ' (ByVal Target As Range)
'Dim ws As Worksheet
'Dim wsL As Worksheet
'Dim pt As PivotTable
'Dim pf As PivotField
'Dim pfD As PivotField
'Dim rngType As Range
'Dim rngTypeSel As Range
'Dim rngNum As Range
'Dim lType As Long
'
'On Error GoTo errHandler
'
'Set ws = ActiveSheet
'Set wsL = Worksheets("Sheet1")
'Set pt = ws.PivotTables("PivotTable1")
'Set pf = pt.RowFields(1)
'Set pfD = pt.DataFields(1)
'Set rngType = ws.Range("TypeSel")
'Set rngTypeSel _
' = wsL.Range("TypeValSel")
'Set rngNum = ws.Range("NumSel")
'
'Select Case Target.Address
' Case rngType.Address, rngNum.Address
' Application.EnableEvents = False
' Application.ScreenUpdating = False
' pf.ClearAllFilters
' If rngNum.Value > 0 And _
' rngTypeSel > 0 Then
' pf.PivotFilters.Add _
' Type:=rngTypeSel.Value, _
' DataField:=pfD, _
' Value1:=rngNum.Value
' End If
'End Select
'
'exitHandler:
' Application.ScreenUpdating = True
' Application.EnableEvents = True
' Exit Sub
'
'errHandler:
' MsgBox "Could not apply filter"
' Resume exitHandler
'End Sub

Avatar
Hans Hallebeek
the Netherlands
Member
Members


Trusted Members
Level 0
Forum Posts: 182
Member Since:
October 17, 2018
sp_UserOfflineSmall Offline
2
August 21, 2023 - 3:53 pm
sp_Permalink sp_Print

Just a point of attention, in your question you talk abou Sheet 2 which is not named as such.

I also suggest you indicate the Excev version you're using in your profile

Avatar
Mark Milan
Member
Members
Level 0
Forum Posts: 29
Member Since:
March 17, 2020
sp_UserOfflineSmall Offline
3
August 21, 2023 - 5:13 pm
sp_Permalink sp_Print

Hi,

I'm sorry, the original post contained a typing error.

I meant to open "Sheet3", instead of "Sheet2" that obviously does not exist.

I use Microsoft365

 

thanks

regards

Mark

Avatar
Hans Hallebeek
the Netherlands
Member
Members


Trusted Members
Level 0
Forum Posts: 182
Member Since:
October 17, 2018
sp_UserOfflineSmall Offline
4
August 22, 2023 - 4:36 pm
sp_Permalink sp_Print

Clear, I'll check and see if I can come up with something, I'm not that hot with Pivot Tables

Avatar
Mark Milan
Member
Members
Level 0
Forum Posts: 29
Member Since:
March 17, 2020
sp_UserOfflineSmall Offline
5
August 23, 2023 - 12:30 am
sp_Permalink sp_Print

Thank you very in advance !

I'd appreciate that very much 🙂

 

Mark

Avatar
Hans Hallebeek
the Netherlands
Member
Members


Trusted Members
Level 0
Forum Posts: 182
Member Since:
October 17, 2018
sp_UserOfflineSmall Offline
6
September 6, 2023 - 6:45 pm
sp_Permalink sp_Print

Hi Mark,

I haven't forgotten you but I don't know where the time goes.

Cheers, 

Hans

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Susan VanRiper, Pedro Llobell, Lorna Henning, Joaquim Amorim
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
jaryszek: 183
Newest Members:
David von Kleek
Ronald White
Ginette Guevremont
Taryn Ambrosi
Mark Davenport
Christy Nichols
Harald Endres
Ashley Hughes
Herbie Key
Trevor Pindling
Forum Stats:
Groups: 3
Forums: 24
Topics: 6528
Posts: 28594

 

Member Stats:
Guest Posters: 49
Members: 32817
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.