Multiple Pivot Table Page Field Link to spreadsheet Cell (All) Exception

Rowland Hamilton

Active Member
Joined
Nov 13, 2009
Messages
250
How do I make this work?

I found this code online but it does not work for the section that deals with the exception for <>target.value that should force the pivots to equal (All).
Here is the section:
If pf.CurrentPage <> Target.Value Then
pf.CurrentPage = "(All)"
End If
If pf2.CurrentPage <> Target.Value Then
pf2.CurrentPage = "(All)"
End IfWhen I keep this section, The page fields stay as "(All)" even when I change the target cell value to another matching value in the pivot table items list (I'm using a drop down list 1-12 and (All)).

When I don't include this section, pivot tables change with the input in the cell until I choose an input that is not included in the field item list, in which case it stays with the last good input value. A better result than only one output, but Ideally I would like it to change for all valid inputs.

Full Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim pt2 As PivotTable
Dim pf2 As PivotField
Dim pi2 As PivotItem
Set pt = Sheets("Pivot").PivotTables("PivotTable1")
Set pt2 = Sheets("Pivot2").PivotTables("PivotTable1")
Set pf = pt.PivotFields("ARF")
Set pf2 = pt2.PivotFields("ARF")

If Target.Address = "$K$2" Then
For Each pi In pf.PivotItems
If pi = Target.Value Then
pf.CurrentPage = Target.Value
Exit For
End If
Next pi

For Each pi2 In pf2.PivotItems
If pi2 = Target.Value Then
pf2.CurrentPage = Target.Value
Exit For
End If
Next pi2

If pf.CurrentPage <> Target.Value Then
pf.CurrentPage = "(All)"
End If
If pf2.CurrentPage <> Target.Value Then
pf2.CurrentPage = "(All)"
End If

End If

End SubThank you, Rowland
 
Last edited:
It would be very helpful if you surrounded your VBA code with [ CODE] [/CODE] tags. Select your VBA code in the forum editor and then click on the pound # icon. It makes reading your code so much easier.

You already have example code (post #7) to display an error message if the user selects a month that is not available in the pivot table.

If you want to have the Data Validation Drop-down List only have the month numbers available in the data (column F), maybe try something like this...
Code:
=OFFSET($G$1,,,MONTH(MAX($F:$F)))

In this example...
Column F has the dates of your data,
G1 to G12 just have 1,2,3... 11,12
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,216,075
Messages
6,128,668
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top