Macro for creating pivot table in Excel 2016

jeff_cp

Board Regular
Joined
May 21, 2015
Messages
84
I have a data source that I need to create a pivot table for each day. The number of rows in the data source will change each day so using the following won't work. I need the macro to look at the last row of data and adjust accordingly. Any help would be greatly appreciated.

Sub Pivot()
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"No Primary Images!R1C1:R6729C4", Version:=6).CreatePivotTable _
TableDestination:="PivotTable!R1C1", TableName:="PivotTable8", _
DefaultVersion:=6
Sheets("PivotTable").Select
Cells(1, 1).Select
With ActiveSheet.PivotTables("PivotTable8").PivotFields("Yard#")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable8").AddDataField ActiveSheet.PivotTables( _
"PivotTable8").PivotFields("GUID"), "Count of GUID", xlCount
ActiveSheet.PivotTables("PivotTable8").AddDataField ActiveSheet.PivotTables( _
"PivotTable8").PivotFields("IMS"), "Count of IMS", xlCount
With ActiveSheet.PivotTables("PivotTable8").PivotFields("Beta")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable8").PivotFields("Count of IMS")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable8").PivotFields("Yard#").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable8").PivotFields("GUID").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable8").PivotFields("IMS").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable8").PivotFields("Beta").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable8").RowAxisLayout xlTabularRow
Cells.Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Cells.EntireColumn.AutoFit
Range("D2").Select
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,215,059
Messages
6,122,917
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