• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Pivot Table Design

Shay A

Member
Hello,
I would like to have a code on my personal macro wb that design the pivot tble to my liking. I am aware that it is possible to save a trmplate of a pivot and to set is as the default. However, every time that I export data to Excel, it doesn't use the deafualt that I want. so, I need your help with the following code:

Code:
Sub Macro3()

  Range("B6").Select
  With ActiveSheet.PivotTables("PivotTable2")
  .DisplayErrorString = True
  .ErrorString = "0"
  .InGridDropZones = False
  End With
  ActiveSheet.PivotTables("PivotTable2").TableStyle2 = "PivotStyleLight16"
End Sub

How do I make the code to work on the current pivot table I am on. Is there an object activepivottable, like there is activecell? Or, maybe I should use for each loop, where the collection is pivottables?


TY
 
Last edited by a moderator:
Something like this.
Code:
Sub test()
Dim pvt As PivotTable
On Error GoTo NoPivot:
Set pvt = ActiveCell.PivotTable
With pvt
    .DisplayErrorString = True
    .ErrorString = "0"
    .InGridDropZones = False
    .TableStyle2 = "PivotStyleLight16"
End With

NoPivot:
If Err.Number = 1004 Then
    MsgBox "Select a cell within PivotTable Range"
End If

End Sub
 
Back
Top