Excel VBA - Grouping Dates

GaryNet0430

New Member
Joined
Apr 3, 2019
Messages
1
I have a very large spreadsheet of data with dates (confirmed that they are proper dates to Excel as opposed to strings) that I am trying to group via VBA. When I run the code, I get an error.

With ptTable

' Set the row fields
.PivotFields("REALDATE").Orientation = xlRowField
'.PivotFields("OPNDTE (Month)").Orientation = xlRowField
.PivotFields("REASON").Orientation = xlRowField

' Add CDB_CATEGORY as filter - and set filter as 500
.PivotFields("CDB_CATEGORY").Orientation = xlPageField
.PivotFields("CDB_CATEGORY").CurrentPage = "Thermatech "

' Set the column fields
'.PivotFields("Title").Orientation = xlColumnField

' Set the data(value) fields
.PivotFields("DIVISION").Orientation = xlDataField
'.PivotFields("OPNDTE").Orientation = xlDataField

' Group the date by year and month
.PivotFields("REALDATE").LabelRange.Group _
Start:=True, End:=True, _
Periods:= _
Array(False, False, False, False, True, False, True)

End With

Done:
Exit Sub
EH:
MsgBox Err.Description & " BuildPivot.CreatePivot"
End Sub

The error is "Group method of Range class failed." Every example I've looked at shows that this should work. But, there is probably something really simple that I am missing.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,854
Messages
6,121,941
Members
449,056
Latest member
denissimo

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