code stuck at pivot creation

my code is running, but stops at creating the pivot table.
Sub MakePivot()
.......
'create pivot cache
Set PtCache = ActiveWorkbook.PivotCaches.Add( _
    SourceType:=xlDatabase, _
    SourceData:=s.Range("F_Data")) 'entire contents of sheet

Can anyone help?
test.xlsb
Euro5Asked:
Who is Participating?
 
Saurabh Singh TeotiaCommented:
Use this code...

Sub MakePivot()
'declare the row, column, page and data field variables
Dim Pt As PivotTable
Dim PtCache As PivotCache
Dim rng As Range, s As Worksheet, s1 As Worksheet
Dim lrow As Long, Lcol As Long
Application.ScreenUpdating = False

  

Set s = Sheets("Filtered_Data")

lrow = s.Cells(Cells.Rows.Count, "A").End(xlUp).Row
Lcol = s.Cells(1, "a").End(xlToRight).Column

Set rng = s.Range("A1:" & Cells(lrow, Lcol).Address)

Sheets.Add
ActiveSheet.Name = "Report"
Set s1 = ActiveSheet


  ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Filtered_Data!" & rng.Address).CreatePivotTable TableDestination:=s1.Range("A3"), TableName:="MWTShipments"

  Set Pt = s1.PivotTables("MWTShipments")

'create pivot table from cache

    
'add fields
    With Pt
    .PivotFields("Date Delivered").Orientation = xlRowField
    .PivotFields("Pay Type").Orientation = xlRowField
    .PivotFields("Origin Zip").Orientation = xlRowField
    .PivotFields("Recipient Zip").Orientation = xlRowField
    .PivotFields("State").Orientation = xlRowField
    .PivotFields("City").Orientation = xlRowField
    .PivotFields("Street Address").Orientation = xlRowField
    .PivotFields("Zone").Orientation = xlRowField
    .PivotFields("Rated Weight").Orientation = xlDataField
    .PivotFields("Ground Rates").Orientation = xlDataField
End With

With Pt
    .DataPivotField.Orientation = xlColumnField
    .ColumnGrand = False
    .RowGrand = False
    .PivotFields("Date Delivered").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
    .PivotFields("Pay Type").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
    .PivotFields("Origin Zip").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
    .PivotFields("Recipient Zip").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
    .PivotFields("State").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
    .PivotFields("City").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
    .PivotFields("Street Address").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
    .PivotFields("Zone").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
End With


Worksheets("Report").Columns("A:DD").AutoFit
Application.ScreenUpdating = True

End Sub

Open in new window


Rather creating cache and then creating pivot table on it..i created the same in one go and in additional since your data is huge thats the reason pivot table is acting a bit in vb code but the enclosed code will work...

Saurabh...
0
 
Saurabh Singh TeotiaCommented:
I'm not able to download your file as it failed after half download..tried couple of times..can you please upload your file again...
0
 
Euro5Author Commented:
I will try Sure hope that you can help....I really have a need for this.
THANKS!
test.xlsb
0
 
Euro5Author Commented:
THANK YOU. Very helpful - understood the issue and corrected. Above and beyond. :)
0
 
Saurabh Singh TeotiaCommented:
You are welcome..Thanks for Appreciating..Happy to Help.. :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.