我的代码有什么问题?
我收到了错误
方法激活工作表失败
Sub addMOnth()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
If ws.Name <> "SUMMARY" And ws.Name <> "Store" And ws.Name <> "Apps" Then
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Report Date Structure].[Month].[Month]").VisibleItemsList = Array( _
"[Report Date Structure].[Month].&[2.01711E5]")
End If
Next ws
End Sub
答案 0 :(得分:1)
Activate
ws
无需过滤PivotTable
。
尝试下面的代码,代码注释中的解释:
Sub addMOnth()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
With ws
Select Case .Name
Case "SUMMARY", "Store", "Apps"
' do nothing
Case Else ' equivalent to your If with multiple AND
.PivotTables("PivotTable1").PivotFields( _
"[Report Date Structure].[Month].[Month]").VisibleItemsList = Array( _
"[Report Date Structure].[Month].&[2.01711E5]")
End Select
End With
Next ws
End Sub