Pivot table in new Worksheet

L

Legacy 108787

Guest
My VB code makes a new worksheet for every PT (or rather will in the near future). I'm trying to get that to work, but I ran into some problems with TableDestination.

Rich (BB code):
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "'Data'!" & Rng2.Address(ReferenceStyle:=xlR1C1)).CreatePivotTable TableDestination:= _
        "'[Master-File.xls]Analyse'&Nn&''!R9C1 TableName:="meldingen_sectie", DefaultVersion _
        :=xlPivotTableVersion10

The worksheet has a variable name, Analyse1, Analyse2, etc.
The code I pasted up there doesn't work, nor do double quotes or no quotes.

Is there a way to have a variable TableDestination in this expression?
 
Last edited by a moderator:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You need something like:
Rich (BB code):
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "'Data'!" & Rng2.Address(ReferenceStyle:=xlR1C1)).CreatePivotTable _
TableDestination:="'[Master-File.xls]Analyse" & Nn & "'!R9C1", _
TableName:="meldingen_sectie", DefaultVersion:=xlPivotTableVersion10
 
Upvote 0
That works indeed. I never knew spaces could make such a difference.

"'[Master-File.xls]Analyse" &Nn& "'!R9C1" throws an "Expected: End of Statement"
"'[Master-File.xls]Analyse" & Nn & "'!R9C1" works smoothly....
 
Upvote 0
It wasn't just the spaces. It was also the misplacing of single and double quotes.
I have tried all possible combinations of quotes before I posted the question here, the final solution without spaces was actually my original try, so it does appear the spaces were the essence of my misfortune.
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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