How do I suppress Excel message for any pivot table update?

故事扮演 提交于 2020-01-05 20:02:32

问题


I have created a pivot table to summarize some information and have added some formulas adjacent to the pivot table to do calculations on the numbers included in it. I have created a macro that re-enters the formulas whenever the user changes the size of the pivot table (in the PivotTableUpdate event) by showing or hiding various rows/columns of data.

My problem is that whenever columns of data are added to the pivot table, it asks me "Do you want to replace the contents of the destination cells?" I always click yes, because although the cells will be overwritten when the pivot table expands, the formulas will be re-entered in their correct cell and everything is fixed and formatted properly by the macro.

Therefore, I would like to know where I should put application.displayalerts = false so that it is effective to suppress the message box whenever the user expands the pivot table.


回答1:


Hi tlewis3348 i think this is what you are looking for

Sub UpdateIt() 
    Dim iP As Integer 
    Application.DisplayAlerts = False 
    For iP = 1 To ActiveSheet.PivotTables.Count 
        ActiveSheet.PivotTables(iP).RefreshTable 
    Next 
    Application.DisplayAlerts = True 
End Sub 



回答2:


FWIW This solution worked great for me. I just activated each sheet individually and called the UpdateIt function before doing anything else, e.g.,

Worksheets("RFS Monthly Summary").Activate
UpdateIt
Worksheets("RFS Daily Activity").Activate
UpdateIt


来源:https://stackoverflow.com/questions/21834775/how-do-i-suppress-excel-message-for-any-pivot-table-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!