我录制了这个宏来更新16个图表的日期范围。但是,正如您所看到的,我得到了一个运行时错误。
我已经看过与此相关的stackoverflow上的其他线程,但都不能接近。excel上的帮助按钮也帮不上忙。你能给点建议吗?代码如下:
ActiveSheet.ChartObjects("Chart 18").Activate
ActiveChart.Axes(xlCategory).Select
ActiveSheet.ChartObjects("Chart 18").Activate
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Date")
.PivotItems("Sep-15").Visible = False
.PivotItems("Aug-14").Visible = True
End With
发布于 2015-10-03 03:36:08
这里有一些简单的代码,可以让您更接近。您需要将此代码中的"MySheet“更改为工作簿中包含透视表的工作表的名称,并且日期字段必须真正采用"Mmm-YY”格式的文本格式。
Sub ShowThirteenDatesStartingLastMonth()
Sheets("MySheet").PivotTables("PivotTable2").PivotCache.Refresh
Dim Dt As String
With Sheets("MySheet").PivotTables("PivotTable2").PivotFields("Date")
For h = 1 To .PivotItems.Count - 1
On Error Resume Next
.PivotItems(h).Visible = False
Next h
For i = 1 To 13
On Error Resume Next
Dt = Format(DateSerial(Year(Date), Month(Date) - i, 1), "Mmm-YY")
.PivotItems(Dt).Visible = True
Next i
End With
End Sub
https://stackoverflow.com/questions/32892267
复制相似问题