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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.