我正在尝试使用VBA更新数据透视表,但是我的下面代码没有得到更新,一旦第一个标准是隐藏休息没有自动隐藏,我迷失了。任何支持都非常有用,附上截图后代码执行。
Sub Pivotselection()
Sheets("Daily Facing Service by WH").Select
Application.ScreenUpdating = False
ActiveSheet.PivotTables("PivotTable1").PivotFields("Ordtype").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable1").PivotFields("TOTLNS").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable1").PivotFields("TOTFCA").Orientation = xlHidden
With ActiveSheet.PivotTables("PivotTable1").PivotFields("WH")
.Orientation = xlColumnField
.Position = 1
End With
Application.ScreenUpdating = True
Sheets("Monthly Facing Service").Select
ActiveSheet.PivotTables("PivotTable4").PivotFields("Ordtype").Orientation = xlHidden
Sheets("Calculations").Select
Range("E8").Select
End Sub
答案 0 :(得分:1)
你的名字不正确。由于它们已添加到值字段,因此名称已更改,因此您需要使用新名称
引用它们Sub Pivotselection()
Sheets("Daily Facing Service by WH").Select
Application.ScreenUpdating = False
ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of Ordtype").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of TOTLNS").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of TOTFCA").Orientation = xlHidden
With ActiveSheet.PivotTables("PivotTable1").PivotFields("WH")
.Orientation = xlColumnField
.Position = 1
End With
Application.ScreenUpdating = True
Sheets("Monthly Facing Service").Select
ActiveSheet.PivotTables("PivotTable4").PivotFields("Ordtype").Orientation = xlHidden
Sheets("Calculations").Select
Range("E8").Select
End Sub
另外,我会删除你的.Select
陈述。他们似乎没有做任何事情