简体   繁体   中英

Worksheet(“Name”).Refresh?

I am currently attempting to optimize some code. Currently, I use ActiveWorkbook.RefreshAll which slows the whole run time down significantly, in actual fact I only need to refresh two worksheet in the workbook. Does a function such as Worksheet("Name").RefreshAll exist? I am aware of .calculate, but I don't think it will update my pivot tables as well as calculation in the given sheets.

Regards

Why not loop through your workbook, and on those specific sheets, calculate and refresh the pivot table? If the tables aren't on the same sheet, you can tweak the code to loop through pivot tables and refresh that way, instead of within the "each sheet" loop.

Sub t()
Dim ws As Worksheet
Dim pvt As PivotTable

For Each ws In ActiveWorkbook.Worksheets
    If ws.Name = "Sheet4" Or ws.Name = "Sheet2" Then
        ws.Calculate
        For Each pvt In ws.PivotTables
            pvt.RefreshTable
        Next pvt
    End If
Next ws

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM