Pivot table VBA Error 1004

MinMax

New Member
Joined
Jan 14, 2021
Messages
5
I get the error code 1004 "unable to get the label range property of the pivot field class"
for the pivot code below:

Sub DateFilter_DAILY()
Sheets("Sales").Activate
'Set the Variables to be used
Dim pt As PivotTable
Set pt = Worksheets("ORDERBOOK").PivotTables("PivotTable4")
pt.PivotCache.REFRESH


'Group Date Field by Month
pt.RowAxisLayout xlTabularRow
Set df = pt.PivotFields("so_invoice_date")
df.LabelRange.Group _
Start:=True, End:=True, _
Periods:=Array(False, False, False, False, True, False, True) 'Seconds-->Minutes-->Hours-->Days-->Months-->Quarters-->Years
pt.RowAxisLayout xlCompactRow

'Set day range on pivot
pt.PivotFields("so_invoice_date").ClearAllFilters 'This line is needed to clear existing filter before applying new one
pt.PivotFields("so_invoice_date").PivotFilters.Add Type:=xlDateBetween, _
Value1:=CLng((Range("u4").Value)), Value2:=CLng((Range("v4").Value))


'Group Date Field by Day
pt.RowAxisLayout xlTabularRow
Set df = pt.PivotFields("so_invoice_date")
df.LabelRange.Group _
Start:=True, End:=True, _
Periods:=Array(False, False, False, True, True, False, True) 'Seconds-->Minutes-->Hours-->Days-->Months-->Quarters-->Years
pt.RowAxisLayout xlCompactRow

Application.DisplayAlerts = False



please help



End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,216,066
Messages
6,128,568
Members
449,458
Latest member
gillmit

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