Error setting value in 2 pivot tables

gio123bg

Active Member
Joined
Feb 14, 2004
Messages
255
Hi All,
I'm tying to set a value of a filter of the pivot A on the same filter of the pivot B. More exactly this is my VBA code.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B2")) Is Nothing Then
If Sheet3.PivotTables("PivotTable1").PivotFields("ORG").CurrentPage <> "(All)" Then
Sheet6.PivotTables("PivotTable1").PivotFields("ORG").CurrentPage = _
Sheet3.PivotTables("PivotTable1").PivotFields("ORG").CurrentPage
End If
End If

End Sub

When I set a value (the same on both pivot tables) in pivot A, I receive this error message

Run-time error '1004':
Unable to set the _Default property of the PivotItem class [End] [Debug] [Help]

Any help will be well appreciated.

Thanks in advance for your king support.

Regards,

Giovanni
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi Andrew,
first of all thanks for your quick replay and support.

In both pivots I have the same name of the filed (for example "ORG") and the same values related to this field/filter.

Let me know if you need more information.

Thanks in advance.

Regards,

Giovanni
 
Upvote 0
What are the PivotItems for ORG in the PivotTable on Sheet3 and which is selected when the event fires? And what are the PivotItems for ORG in the PivotTable on Sheet6 and which is selected?
 
Upvote 0
Ok
The value that I set in PivotTable1 on Sheet3 for field "ORG" is "OTH". For Sheet6 the value allowed for the filter "ORG" is "OTH". The same value.

If I change the code in

If Not Intersect(Target, Range("B2")) Is Nothing Then
If Sheet3.PivotTables("PivotTable1").PivotFields("ORG").CurrentPage <> "(All)" Then
Sheet6.PivotTables("PivotTable1").PivotFields("Org").CurrentPage = "OTH"
End If
End If

The macro works correctly.

Any idea?

Thanks in advance for your kind support.

Regards,

Giovanni
 
Upvote 0
Hi Andrew,
Now the macro works correctly using a variable without a type defined.

var1 = Sheet3.PivotTables("PivotTable1").PivotFields("ORG").CurrentPage
Sheet6.PivotTables("PivotTable1").PivotFields("Org").CurrentPage = var1

This is strange but now it's Ok!

Thanks again for your kind support.

Regards,

Giovanni
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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