HFX_Martin
New Member
- Joined
- Nov 12, 2021
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
I have created a program that adds dates to the column of a pivot table and then groups the dates by year and month. Here is the section of code that performs this function:
I am running this code successfully against many workbooks, however I have run into one issue. Some of the workbooks have more than 16384 unique "Entered On" entries which exceeds the amount of columns allowed in a pivot chart. When the program initially tries to add the "Entered On" date, the program breaks. I need to group the dates by year/month before (or while) adding them to the pivot table to avoid breaking the column limit.
I would like to avoid using the .AutoGroup function. The data within each workbook can vary and 'AutoGroup causes inconsistent results.
Any thoughts?
Thanks!
VBA Code:
' Add "EnteredOn dates field to pivot table column
With ActiveSheet.PivotTables("Report_Usage").PivotFields("EnteredOn")
.Orientation = xlColumnField
.Position = 1
End With
'Group EnteredOn dates by years and months
Dim rngGroup As Range
Set rngGroup = ActiveSheet.PivotTables("Report_Usage").PivotFields("EnteredOn").DataRange
rngGroup.Cells(1).Group Start:=True, End:=True, Periods:=Array(False, False, False, False, True, False, True)
I am running this code successfully against many workbooks, however I have run into one issue. Some of the workbooks have more than 16384 unique "Entered On" entries which exceeds the amount of columns allowed in a pivot chart. When the program initially tries to add the "Entered On" date, the program breaks. I need to group the dates by year/month before (or while) adding them to the pivot table to avoid breaking the column limit.
I would like to avoid using the .AutoGroup function. The data within each workbook can vary and 'AutoGroup causes inconsistent results.
Any thoughts?
Thanks!