Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Rename a worksheet to use with a pivot table

I am consolidating date every two weeks into this workbook and each time I
will change the worksheet name to match the current period i.e. "Period X".
I have the pivot table on another worksheet and want to automatically change
the source data worksheet name to match the current period or allow a user to
input the current period number. Here is the code I have for doing this, but
I have a syntax error I cannot figure out.
PeriodNumber = InputBox(Prompt:="Enter the Period Number for the Summary
Report", Title:="Summary Report Period")
WSName = "Period " & PeriodNumber

'The error is in this portion of the code

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
WorkSheet("WSName").Range("C10:C14").CreatePivotTa ble(TableDestination:="'Period Report'!R3C1", TableName:="PivotTable2")

ActiveSheet.PivotTables("PivotTable2").RowGrand = False
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array( _
"Billing Code", "Client Name", "Project No."), ColumnFields:="Name"
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("Total")
.Orientation = xlDataField
.Caption = "Sum of Total"
.Function = xlSum
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Rename a worksheet to use with a pivot table

Try...

...., sourcedata:=WorkSheet(WSName).range(....

(drop the double quotes)

David J wrote:

I am consolidating date every two weeks into this workbook and each time I
will change the worksheet name to match the current period i.e. "Period X".
I have the pivot table on another worksheet and want to automatically change
the source data worksheet name to match the current period or allow a user to
input the current period number. Here is the code I have for doing this, but
I have a syntax error I cannot figure out.
PeriodNumber = InputBox(Prompt:="Enter the Period Number for the Summary
Report", Title:="Summary Report Period")
WSName = "Period " & PeriodNumber

'The error is in this portion of the code

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
WorkSheet("WSName").Range("C10:C14").CreatePivotTa ble(TableDestination:="'Period Report'!R3C1", TableName:="PivotTable2")

ActiveSheet.PivotTables("PivotTable2").RowGrand = False
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array( _
"Billing Code", "Client Name", "Project No."), ColumnFields:="Name"
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("Total")
.Orientation = xlDataField
.Caption = "Sum of Total"
.Function = xlSum
End With
End Sub


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to rename a GROUP in a Pivot table spudsnruf Charts and Charting in Excel 6 April 4th 23 10:25 AM
rename groups in Pivot table Kermit Excel Discussion (Misc queries) 1 July 8th 08 08:50 AM
REname Pivot table columns HSalim[MVP] Excel Programming 0 April 25th 07 06:13 AM
Using VBA to rename Pivot Table Query Ron McCormick[_3_] Excel Programming 3 November 7th 03 03:28 AM
Using VBA to rename Pivot Table Query Ron McCormick[_2_] Excel Programming 0 November 6th 03 10:11 AM


All times are GMT +1. The time now is 09:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"