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