98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel Training and help » Pivot table usage within macros
Pivot table usage within macros
Resolved · Low Priority · Version 2007
Stephen has attended:
Excel Advanced course
Pivot table usage within macros
When a pivot table is created in a macro the pivot is created in a new sheet which is automatically named Sheet[next number].
Unfortunately this renders the macro unworkable unless by sheer chance the [next number] when the macro is run is the same as the [next number] when the macro was recorded.
Is there a way of naming the sheets on creation to avoid this issue?
RE: Pivot table usage within macros
Hello Stephen,
You could name the sheet before the Pivot is created. Below is the code, it should be identical to your recorded code. I have only included the first part.
The parts you need to change are:
After the Sheets.add, put the inputbox command to accept a name for new sheet.
Look for the Table Destination property and follow this with the Activesheet command and the cell location.
if your code has the 2 lines below the pivot command, mine here shows Sheets 5 and Cells etc.. just comment these out or delete.
hope that helps
Sheets.Add
ActiveSheet.Name = InputBox("Enter name")
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
Sheets("Mark Moore").Range("A10").CurrentRegion, Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:=ActiveSheet.Range("A1"), TableName:="PivotTable2", DefaultVersion _
:=xlPivotTableVersion14
' Sheets("Sheet5").Select
' Cells(3, 1).Select
I hope this resolves your question. If it has, please mark this question as resolved.
If you require further assistance, please reply to this post. Or perhaps you have another Microsoft Office question?
Have a great day.
Regards,
Mark
Microsoft Office Specialist Trainer
Training information:
See also:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Add a € to your cellsIf you need to add a € symbol to your Excel sheet - hold down the key Alt Gr and 4. |