Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using VBA to rename Pivot Table Query

I wish to copy a pivot table report and name
it "PivotTable_2". How do I do this programmatically? I
tried recording a macro and came up with the following:

ActiveSheet.PivotTables("PivotTable1").PivotSelect "",
xlDataAndLabel
Selection.Copy
Application.Goto Reference:="Target_Region"
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.PivotTables("PivotTable8").Name
= "PivotTable_2"

The problem is that next time I run the procedure the
Pivot Table to be named "PivotTable_2" is "PivotTable9".
How do I get the table to be "PivotTable8" each time? (If
I knew that I wouldn't actually need to rename it
as "PivotTable_2"!).

TIA
Ron

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Using VBA to rename Pivot Table Query

This seemed to work ok for me:

Option Explicit
Sub testme()

With ActiveSheet
.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel
Selection.Copy
Application.Goto Reference:="Target_Region"
End With

With ActiveSheet
.Paste
Application.CutCopyMode = False
.PivotTables(.PivotTables.Count).Name = "PivotTable_2"
End With

End Sub

The last pivottable added is .pivottables.count.



Ron McCormick wrote:

I wish to copy a pivot table report and name
it "PivotTable_2". How do I do this programmatically? I
tried recording a macro and came up with the following:

ActiveSheet.PivotTables("PivotTable1").PivotSelect "",
xlDataAndLabel
Selection.Copy
Application.Goto Reference:="Target_Region"
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.PivotTables("PivotTable8").Name
= "PivotTable_2"

The problem is that next time I run the procedure the
Pivot Table to be named "PivotTable_2" is "PivotTable9".
How do I get the table to be "PivotTable8" each time? (If
I knew that I wouldn't actually need to rename it
as "PivotTable_2"!).

TIA
Ron


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Using VBA to rename Pivot Table Query

Dave,

Thanks so very very much for your response. I think it
gets close to what I'm after, however perhaps I'm still
doing something not quite right as when I run this
procedure my PivotTable1 has its name changed to
PivotTable_2, rather than the copy. And even if I change
PivotTable1's name to PivotTable_Base it still changes
it's rather than the new table's name to PivotTable_2.

I would appreciate any further thoughts from you or others.

Many thanks again for your response.
Ron
-----Original Message-----
This seemed to work ok for me:

Option Explicit
Sub testme()

With ActiveSheet
.PivotTables("PivotTable1").PivotSelect "",

xlDataAndLabel
Selection.Copy
Application.Goto Reference:="Target_Region"
End With

With ActiveSheet
.Paste
Application.CutCopyMode = False
.PivotTables(.PivotTables.Count).Name

= "PivotTable_2"
End With

End Sub

The last pivottable added is .pivottables.count.



Ron McCormick wrote:

I wish to copy a pivot table report and name
it "PivotTable_2". How do I do this programmatically?

I
tried recording a macro and came up with the following:

ActiveSheet.PivotTables("PivotTable1").PivotSelect "",
xlDataAndLabel
Selection.Copy
Application.Goto Reference:="Target_Region"
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.PivotTables("PivotTable8").Name
= "PivotTable_2"

The problem is that next time I run the procedure the
Pivot Table to be named "PivotTable_2" is "PivotTable9".
How do I get the table to be "PivotTable8" each time?

(If
I knew that I wouldn't actually need to rename it
as "PivotTable_2"!).

TIA
Ron


--

Dave Peterson

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Using VBA to rename Pivot Table Query

I could reproduce it if the pivottable1 were already located on the
range("target_region").

Is it possible that you're copying the pivottable on top of itself (not changing
anything but its name)???

If my pivottable1 were in a different worksheet (or if pivottable1 weren't on
target_region), then the code worked ok for me.

Maybe you could be a little more explicit by avoiding the activesheet.

Option Explicit
Sub testme()

With worksheets("myWksheet")
.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel
Selection.Copy
Application.Goto Reference:="Target_Region"
End With

' With ActiveSheet 'target_region's worksheet
with thisworkbook.names("target_region").referstorange. parent
.Paste
Application.CutCopyMode = False
.PivotTables(.PivotTables.Count).Name = "PivotTable_2"
End With

End Sub

If that's not it, I'm at a loss.

Ron McCormick wrote:

Dave,

Thanks so very very much for your response. I think it
gets close to what I'm after, however perhaps I'm still
doing something not quite right as when I run this
procedure my PivotTable1 has its name changed to
PivotTable_2, rather than the copy. And even if I change
PivotTable1's name to PivotTable_Base it still changes
it's rather than the new table's name to PivotTable_2.

I would appreciate any further thoughts from you or others.

Many thanks again for your response.
Ron
-----Original Message-----
This seemed to work ok for me:

Option Explicit
Sub testme()

With ActiveSheet
.PivotTables("PivotTable1").PivotSelect "",

xlDataAndLabel
Selection.Copy
Application.Goto Reference:="Target_Region"
End With

With ActiveSheet
.Paste
Application.CutCopyMode = False
.PivotTables(.PivotTables.Count).Name

= "PivotTable_2"
End With

End Sub

The last pivottable added is .pivottables.count.



Ron McCormick wrote:

I wish to copy a pivot table report and name
it "PivotTable_2". How do I do this programmatically?

I
tried recording a macro and came up with the following:

ActiveSheet.PivotTables("PivotTable1").PivotSelect "",
xlDataAndLabel
Selection.Copy
Application.Goto Reference:="Target_Region"
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.PivotTables("PivotTable8").Name
= "PivotTable_2"

The problem is that next time I run the procedure the
Pivot Table to be named "PivotTable_2" is "PivotTable9".
How do I get the table to be "PivotTable8" each time?

(If
I knew that I wouldn't actually need to rename it
as "PivotTable_2"!).

TIA
Ron


--

Dave Peterson

.


--

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
How do you rename table headers in a query using Offic 07? DFoster Excel Worksheet Functions 3 August 29th 08 01:48 PM
Need to rename table columns in excel from a query DFoster Excel Worksheet Functions 3 August 26th 08 10:24 PM
rename groups in Pivot table Kermit Excel Discussion (Misc queries) 1 July 8th 08 08:50 AM
Pivot Table Query sgriff Excel Discussion (Misc queries) 0 July 21st 06 08:08 AM


All times are GMT +1. The time now is 11:15 PM.

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

About Us

"It's about Microsoft Excel"