My macro creates a pivot table but I am running into an issue when it goes to group one of the numeric columns as I get a "Group method of Range class failed" message. The grouping portion of the code is from a recorder. The rest of the code not shown attempts to group three other fields and then finish out. Any thoughts on how to fix this?
Also, I have to create this report weekly so it's a new one each week. Do you see any code issues with the creation of the table? I've noticed that the pivot table # changes each time it gets created so I'm wondering if I need to be more exact? Sorry if that second question is too vague. Thanks!
Pivot table
Dim PTCache As PivotCache
Dim PT As PivotTable
Set PTCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Range("A1").CurrentRegion)
'Adding new sheet for the pivot table
Worksheets.Add
'Creating the Pivot Table
Set PT = ActiveSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=Range("A3"))
ActiveSheet.PivotTables("PivotTable1").RowAxisLayout xlTabularRow
With ActiveSheet.PivotTables("PivotTable1")
.ColumnGrand = False
.RowGrand = False
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Grade 1")
.Orientation = xlRowField
.Position = 1
End With
Selection.Group Start:=True, End:=100, By:=15
ActiveSheet.PivotTables("PivotTable1").PivotFields("Grade 1").Orientation = _
xlHidden
Bookmarks