VBA Change Pivot Filter Based on Cell Value (Pivot from Database)

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
Hi,

I'm trying to change the John Smith part of the below vba so that it will change to whatever is in say Sheet1!A1 for arguments sake.

I can find articles for changing it on a standard Pivot Table but as this is coming from a SQL CUBE pivot table i'm struggling to get the correct syntax.

Can anyone help please? Thanks

Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
        "[Territory].[Territory].[Territory]").VisibleItemsList = Array( _
        "[Territory].[Territory].&[John Smith]")
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try:

Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
        "[Territory].[Territory].[Territory]").VisibleItemsList = Array( _
        "[Territory].[Territory].&[" & Worksheets("Sheet1").Range("A1").Value & "]")
 
Upvote 0
Fantastic, been looking to use something like this for ages, thanks alot Andrew.

Try:

Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
        "[Territory].[Territory].[Territory]").VisibleItemsList = Array( _
        "[Territory].[Territory].&[" & Worksheets("Sheet1").Range("A1").Value & "]")
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

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