Hi, I am attempting to set a filter on an Excel pivot table using a variable in a macro.
When I execute this macro it works ok:
Sheets("Amort").Select
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Receiver].[Rcv 09 Name].[Rcv 09 Name]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Receiver].[Rcv 09 Name].[Rcv 09 Name]").CurrentPageName = _
"[Receiver].[Rcv 09 Name].&[BUSINESS X]"
The 'Rcv 09 Name' filter is set to BUSINESS X
I have another 8 of these command 'sets' in the macro, so one for each of the 9 sheets I need to update.
To save time I'd like to be able to set a BUSINESS name in a variable at the top of the macro and have that substitute into the last field in each set.... i.e. to set the BUSINESS filter
Something like this:
Dim u9name As String
u9name = "BUSINESS X"
Sheets("Amort").Select
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Receiver].[Rcv 09 Name].[Rcv 09 Name]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Receiver].[Rcv 09 Name].[Rcv 09 Name]").CurrentPageName = _
"[Receiver].[Rcv 09 Name].&[u9name]"
What would be the format/method for including the u9name variable in this command?
I have tried a few versions, and checked other threads, but I as yet no luck getting the substitution to work. The debig highlights the second ActivSheet command . I am new to macros so I hope this makes sense.
Using Excel 2007.
Thanks
When I execute this macro it works ok:
Sheets("Amort").Select
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Receiver].[Rcv 09 Name].[Rcv 09 Name]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Receiver].[Rcv 09 Name].[Rcv 09 Name]").CurrentPageName = _
"[Receiver].[Rcv 09 Name].&[BUSINESS X]"
The 'Rcv 09 Name' filter is set to BUSINESS X
I have another 8 of these command 'sets' in the macro, so one for each of the 9 sheets I need to update.
To save time I'd like to be able to set a BUSINESS name in a variable at the top of the macro and have that substitute into the last field in each set.... i.e. to set the BUSINESS filter
Something like this:
Dim u9name As String
u9name = "BUSINESS X"
Sheets("Amort").Select
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Receiver].[Rcv 09 Name].[Rcv 09 Name]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Receiver].[Rcv 09 Name].[Rcv 09 Name]").CurrentPageName = _
"[Receiver].[Rcv 09 Name].&[u9name]"
What would be the format/method for including the u9name variable in this command?
I have tried a few versions, and checked other threads, but I as yet no luck getting the substitution to work. The debig highlights the second ActivSheet command . I am new to macros so I hope this makes sense.
Using Excel 2007.
Thanks