Avatar of shieldsco
shieldsco
Flag for United States of America

asked on 

Excel VBA Error

I'm using the code below and receive  run-time error 1004  unable to get the pivot field property of the Pivot Table Class on line - Set rngGroup = PvtTbl.PivotFields("Dates").DataRange


Sub PivotTableGroupData1()

Dim PvtTbl As PivotTable
Dim rngGroup As Range
Set PvtTbl = Worksheets("Data Chart").PivotTables("PivotTable1")

'set range of dates to be grouped
Set rngGroup = PvtTbl.PivotFields("Dates").DataRange

rngGroup.Cells(1).Group Periods:=Array(False, False, False, False, True, False, False)

'to ungroup:
'rngGroup.Cells(1).Ungroup

End Sub

Open in new window

VBA

Avatar of undefined
Last Comment
shieldsco

8/22/2022 - Mon