Link to home
Create AccountLog in
Avatar of shieldsco
shieldscoFlag 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

Avatar of Louis LIETAER
Louis LIETAER
Flag of France image

Can you provide an excel file example with a manual pivotable that is corresponding to your needs
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of shieldsco

ASKER

Thanks
Thanks