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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

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