+ Reply to Thread
Results 1 to 2 of 2

Change value filter in PIVOT via VBA

  1. #1
    Registered User
    Join Date
    07-24-2017
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    1

    Change value filter in PIVOT via VBA

    Hi,

    I hope someone can help me, regarding change value fields in a pivot using VBA coding. I total I have 4 different fields that I want to users to be able to switch between, Units, Value in EUR, Value in USD and Value in DKK via dedicated buttons. Now here is the problem. Regardless of which of the field are currently in the pivot it should always change to the selected field. I am thinking that an OR function would be able to do the trick but cannot get it to work. Below are the VBAs for changing each of the fields to Units.


    Sub To_DKK()

    To_DKK Macro


    If ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of Sales Units").Orientation = xlHidden Or _
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of Sales EUR Incl. VAT").Orientation = xlHidden Or _
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of Sales USD Incl. VAT").Orientation = xlHidden Then
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
    "PivotTable1").PivotFields("Sales DKK Incl. VAT"), "Sum of Sales DKK Incl. VAT" _
    , xlSum
    Else
    ActiveSheet.PivotTables("PivotTable1").PivotFields ("Sum of Sales DKK Incl. VAT")
    End If

    End Sub

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Change value filter in PIVOT via VBA

    Hi,

    If you only have one data field at a time, you might simply use 4 macros like this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ 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. Help on VBA - change pivot filter fields
    By FixandFoxi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2017, 04:08 AM
  2. Use Cell Value to Change Pivot Filter
    By jrnewport1115 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2014, 06:08 PM
  3. Replies: 6
    Last Post: 07-31-2014, 12:56 PM
  4. VBA to change pivot table filter
    By Nmarkit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2013, 09:44 AM
  5. Change Pivot table Filter Based on Cell Value *Multiple Filter items* Possible?
    By Flydd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-27-2012, 06:57 AM
  6. VBA to change filter for n pivots based on page filter selection for the first pivot
    By shama.arige in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2011, 11:42 AM
  7. Replies: 3
    Last Post: 06-23-2009, 01:36 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