Pivot Table

carddard

Active Member
Joined
Aug 19, 2008
Messages
427
Hi guys,

I need to create a pivot table for all worksheets.
I have dynamic rows in all worksheets.

Here is the code I have.
In the code, ABN refers to worksheet "ABN" only.
However, I need to make this code work for all worksheets with dynamic number of rows.. Anyone can help?

Code:
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "ABN!R1C1:R78C17").CreatePivotTable TableDestination:= _
        "'[Sort Heldsec v7.2 with data.xls]ABN'!R80C1", TableName:="PivotTable1", _
        DefaultVersion:=xlPivotTableVersion10
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("DATE"), "Count of DATE", xlCount
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("DATE")
        .Orientation = xlRowField
        .Position = 1
    End With

Thanks a lot!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Insted of VBA, i would like to suggest to use the Multiple consolidation ranges in pivot wizard. Here you can give the maximum range of sheet you are going to use and generate a pivot table.

check at your end and share your experience.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top