View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
William[_2_] William[_2_] is offline
external usenet poster
 
Posts: 227
Default Pivot Table Name Reset

You could try adding this to your current macro after you have created all
the pivot tables.

Sub test()
Dim i As Integer
Dim ws As Worksheet
For Each ws In Worksheets
If ws.PivotTables.Count 0 Then
For i = 1 To ws.PivotTables.Count
ws.PivotTables(i).Name = "PivotTable" & i + 1000
Next i
For i = 1 To ws.PivotTables.Count
ws.PivotTables(i).Name = "PivotTable" & i
Next i
End If
Next ws
End Sub



--
XL2002
Regards

William



"DNewton " wrote in message
...
| Hello,
| I'm using a macro to import a text file, create two new sheets within
| that file with three pivot tables on each new sheet and save the file
| as an Excel spreadsheet. This basic macro is run for each of several
| text files.
|
| I used the macro record feature to create the pivot tables and these
| are the names Excel assigned to the tables:
|
| Sheet 1: PivotTable1, PivotTable2, PivotTable3
| Sheet 2: PivotTable1, PivotTable4, PivotTable5
|
| When I import the next text file, the names assigned a
|
| Sheet 1: PivotTable1, PivotTable6, PivotTable7
| Sheet 2: PivotTable1, PivotTable8, PivotTable9
|
| Is there any way to reset Excel's internal counter so that each time I
| run the macro the table names will be the same instead of incrementing
| by one each time?
|
| If I go back and try to import the first text file again and the macro
| refers to the original names for formatting the table, I get an error
| because the pivot table has been assigned a different number this time.
|
|
| Thanks!
|
|
| ---
| Message posted from
http://www.ExcelForum.com/
|