• 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.

Where this error in the pivot??

Hi

Please find the attached, the problem with ur macro was the name of the pivot table changes each time u make a new pivot. Hence, you have to make ur pivot table name dynamic.

Thanks
Nebu
 

Attachments

  • CREATE PIVOT-Test.xlsm
    24.1 KB · Views: 4
Code:
Public Sub Create_Pivot_1()

Worksheets("Raw_Data").Activate
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set Rng = Range("A1:G" & lastrow)
Worksheets.Add
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="Raw_Data!" & Rng.Address).CreatePivotTable TableDestination:=ActiveSheet.Range("A1")
   
With ActiveSheet.PivotTables(ActiveSheet.PivotTables.Count).PivotFields("Part")
  .Orientation = xlRowField
  .Position = 1
End With
With ActiveSheet.PivotTables(ActiveSheet.PivotTables.Count).PivotFields("Type")
  .Orientation = xlColumnField
  .Position = 1
End With
ActiveSheet.PivotTables(ActiveSheet.PivotTables.Count).AddDataField ActiveSheet.PivotTables( _
  ActiveSheet.PivotTables.Count).PivotFields("QTY"), "Sum of QTY", xlSum
   
End Sub
 
Back
Top