为什么我的宏必须运行两次才能显示数据透视图?

时间:2019-01-23 16:10:10

标签: excel vba pivot-chart

我的工作簿中有数据透视图。不知何故,当我运行宏时,数据透视表未显示。当我再次运行宏时,将显示数据透视图。怎么会来?

有时,但并非总是如此,下一行会给出错误(在“刷新”部分):         Selection.NumberFormat =“ 0%”

我尝试使用.Visible = True取消隐藏数据透视图的代码。它仍然没有显示数据透视表

Sub CopyOrders()

' Unhide all Sheets
For Each ws In ActiveWorkbook.Worksheets
    ws.Visible = xlSheetVisible
    If ws.AutoFilterMode Or ws.FilterMode Then
        ws.ShowAllData
    End If
    ws.Columns.EntireColumn.Hidden = False
    ws.Rows.EntireRow.Hidden = False
Next ws

ActiveWorkbook.SlicerCaches("Slicer_Site_Peros_Number___Name"). _
    ClearManualFilter

' Other code is showing here to calculate and form the tables my pivotcharts are coming from


' Refresh Output
Sheets("Output Frames").Select
ActiveSheet.PivotTables("PivotTableArticles").PivotCache.Refresh
Sheets("Output Frames").PivotTables("PivotTableArticles").DataBodyRange.NumberFormat = "dd/mm/yyyy"
Sheets("Output Frames").PivotTables("PivotTableSoldPerSite").PivotSelect "Percentage", _
    xlDataAndLabel, True
Selection.NumberFormat = "0%"
Columns("A:R").EntireColumn.AutoFit
Range("A2:P4").Font.Size = 30
Range("A6:P8").Font.Size = 20
Range("A42:P44").Font.Size = 20
Range("A1").Select

' Hide Data
Sheets("Output Frames").Columns("R:XFD").EntireColumn.Hidden = True
Sheets("Output Frames").Columns("H").EntireColumn.Hidden = True
Sheets("Output Frames").Columns("N").EntireColumn.Hidden = True
Sheets("Sales").Visible = xlSheetHidden
Sheets("Orders vs Sales").Visible = xlSheetHidden
Sheets("Sitenumbers").Visible = xlSheetHidden
Sheets("PivotTables").Visible = xlSheetHidden

End Sub

有人可以说出为什么枢纽分析表没有第一次显示怎么解决吗?

0 个答案:

没有答案