我有这段代码可以将我的数据透视表从最后一行更新为52行,它适用于我的另一个数据透视表。但是,在这个枢纽上,我在行unable to get the rowrange property of the pivottable class
上遇到For n = ws.PivotTables("scencount").RowRange.Count To 1 Step -1
错误。我的枢轴在我的活动工作表上,而我的枢轴数据源在另一个工作表上。
Sub MovingPivotirworst()
Dim ws As Worksheet
Dim dtTop As Date
Dim i As Integer, n As Long
Const NumWeeks = 52 'Change this to set weeks range
Set ws = ActiveSheet
'reset the pivot filters
ws.PivotTables("scencount").PivotFields("businessDate").ClearAllFilters
'remove blank values
ws.PivotTables("scencount").PivotFields("businessDate").PivotItems("(blank)").Visible = False
'find the date entry in 50 places from bottom.
i = 0
For n = ws.PivotTables("scencount").RowRange.Count To 1 Step -1
If i = NumWeeks Then
dtTop = ws.PivotTables("scencount").RowRange.Cells(n).Value
Exit For
End If
i = i + 1
Next n
ws.PivotTables("scencount").PivotFields("businessDate").PivotFilters.Add2 Type:=xlAfterOrEqualTo, Value1:=Format(dtTop, "dd-mmm-yyyy")
End Sub
有人可以帮忙吗?谢谢。