Cập nhật nội dung chi tiết về Refresh Pivot Tables Automatically When Source Data Changes mới nhất trên website Beiqthatgioi.com. Hy vọng thông tin trong bài viết sẽ đáp ứng được nhu cầu ngoài mong đợi của bạn, chúng tôi sẽ làm việc thường xuyên để cập nhật nội dung mới nhằm giúp bạn nhận được thông tin nhanh chóng và chính xác nhất.
Bottom Line: Learn how to use a simple macro to refresh pivot tables automatically whenever changes are made to the source data. I also share a non-macro solution to update the pivot tables when the file is opened. Includes video tutorial and Excel file download.
Skill Level: Intermediate
Download the Excel File
If you learn best by doing it on your own, you can download the file I’m using in the video to follow along. Here is the Excel file that contains the VBA code.
Update Pivot Tables Automatically
Can your pivot tables be updated immediately and automatically when their source data changes?
Absolutely. It requires the use of a really simple macro that I will show you how to create below.
Also, if you are new to pivot tables, I have a series to walk you through what they are and how to use them. Watch the first video in that series on Pivot Tables & Dashboards
To automatically update our pivot tables, we are going to write a macro with one simple instruction. That instruction basically says: when I make a change to my worksheet, refresh all the pivot tables and data connections. Here are the steps to create the macro.
1. Open the Visual Basic Editor.
2. Open the Sheet Module that contains your source data.
3. Add a new event for worksheet changes.
Note: The SelectionChange event that is added by default will run any time the user selects a cell in the sheet. Since we only want the code to run when the user edits/changes cells , we use the Change event. Checkout my article on VBA Code Modules & How to Run Macros Based on User Events to learn more about the sheet modules and events.
4. Add the VBA code to refresh all pivot tables.
Next, just below the Worksheet_Change line, type in this instruction:
ThisWorkbook.RefreshAllAdd this line of code to the Worksheet_Change event will refresh the workbook whenever a change is made to the worksheet that the code is in.
Pivot Table & Source Data on Same Sheet
The refresh puts the event in a recursive loop, and can end up crashing Excel. Here is the code to prevent that.
Application.EnableEvents = False ThisWorkbook.RefreshAll Application.EnableEvents = TrueChecking to Ensure Your Macro Is Running
One way to check if the macro is working is to test it. Make a change to the source data and see if it is reflected in your pivot table. If your change isn’t easy to spot because you have too much data, or for some other reason, there’s another way to see if your macro is firing.
The keyboard shortcut to toggle a breakpoint on/off is: F9
Now whenever an action occurs that triggers the macro, Excel will jump to the VB Editor and pause the macro so that you can check the code. In our case, that action is any change being made in the worksheet.
If you make a change to the worksheet and Excel doesn’t pull you into the VB Editor, you know there is a problem with the macro not running. If this is the case, it’s likely that you haven’t saved the file as a macro-enabled workbook (.xlsm), and/or enabled macros. You might need to save & close the file, then re-open it and enable macros.
The keyboard shortcut to clear all breakpoints is: Ctrl+ Shift+ F9
Refreshing Pivot Tables Without a Macro
There is an alternative that allows you to keep your Undo history. However, this alternative only refreshes your pivot table when the workbook is opened, not every time a change is made. Here is how you can use that option.
Starting from any cell in your pivot table:
Go to the Analyze tab in the ribbon.
Choose the Options button.
Go to the Data tab in the new window that opens.
Check the box that says, “Refresh data when opening the file.”
Again, just by way of comparison, if you use this option you retain Undo history, but it only refreshes the pivot table when the workbook is closed and reopened. If you use the macro option, you lose Undo history, but the pivot table automatically updates whenever any change is made in the workbook.
Variations for Refreshing Pivot Tables
The macro we looked at will not only refresh your pivot tables, but will also refresh any queries as well. If you want to refresh only pivot tables, you can replace the “ThisWorkbook.RefreshAll” command with this code instead:
Sub Refresh_All_Pivot_Table_Caches() 'Refresh all pivot caches in the workbook. 'Pivot tables are automatically refreshed when cache is refreshed. Dim pc As PivotCache 'Refresh all pivot tables For Each pc In ThisWorkbook.PivotCaches pc.Refresh Next pc End SubEach pivot table is connected to an underlying pivot cache, which is connected to the source data. The code loops through all pivot caches in the workbook and refreshes each one. Pivot tables from the same source range can share pivot caches, so this method is faster than looping through all pivot tables.
Similarly, let’s say you only want to refresh one particular pivot table. In that case, you can swap out the “ThisWorkbook.RefreshAll” code with the code below.
Use the Deactivate Event Instead
Another option is to use the Worksheet_Deactivate event instead of Worksheet_Change. The Worksheet_Deactivate event will run every time the user leaves the sheet and selects a different sheet. This allows the user to make all the changes to the source data, then the pivot table will be automatically refreshed when they go to any other sheet, including the sheets that contain the pivot table.
Private Sub Worksheet_Deactivate() ThisWorkbook.RefreshAll End SubThis code would still be placed in the sheet module that contains the source data. This is a good option if your pivot tables or data connections take a few seconds or longer to update, and you don’t want to wait every time a change is made to the source data.
The only time you might not want to use this is if your pivot table and source data are on the same sheet. That will usually be a rare case, and something I generally don’t recommend.
Thanks to the suggestion from Ted on this one.
Save Time & Embarrassment
I hope this article helps save you time and makes it easier for users of your files. It can also help prevent embarrassment when you forget to refresh pivot tables before sending out reports. Believe me, I’ve made this mistake more times than I’d like to admit… 🙂
How To Refresh Pivot Table On File Open In Excel?
How to refresh pivot table on file open in Excel?
In default, when you change your data in the table, the relative pivot table will not refresh at the same time. Here I will tell you how to refresh the pivot table when opening the file in Excel.
Refresh pivot table on file open
Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier…
Read More… Free Download…
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
Reuse Anything:
Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
More than 20 text features:
Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
Merge Tools
: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
Split Tools
: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
Paste Skipping
Hidden/Filtered Rows; Count And Sum
by Background Color
; Send Personalized Emails to Multiple Recipients in Bulk.
More than 300 powerful features;
Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.
Read More… Free Download…
Refresh pivot table on file open
Do as follow to set the pivot table refresh when the file is opening.
Relative Articles:
The Best Office Productivity Tools
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
Reuse:
Quickly insert
complex formulas, charts
and anything that you have used before;
Encrypt Cells
with password;
Create Mailing List
and send emails…
Super Formula Bar
(easily edit multiple lines of text and formula);
Reading Layout
(easily read and edit large numbers of cells);
Paste to Filtered Range
…
Merge Cells/Rows/Columns
without losing Data; Split Cells Content;
Combine Duplicate Rows/Columns
… Prevent Duplicate Cells;
Compare Ranges
…
Select Duplicate or Unique
Rows;
Select Blank Rows
(all cells are empty);
Super Find and Fuzzy Find
in Many Workbooks; Random Select…
Exact Copy
Multiple Cells without changing formula reference;
Auto Create References
to Multiple Sheets;
Insert Bullets
, Check Boxes and more…
Extract Text
, Add Text, Remove by Position,
Remove Space
; Create and Print Paging Subtotals;
Convert Between Cells Content and Comments
…
Super Filter
(save and apply filter schemes to other sheets);
Advanced Sort
by month/week/day, frequency and more;
Special Filter
by bold, italic…
Combine Workbooks and WorkSheets
; Merge Tables based on key columns;
Split Data into Multiple Sheets
;
Batch Convert xls, xlsx and PDF
…
More than 300 powerful features
. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
Read More… Free Download… Purchase…
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
Enable tabbed editing and reading in Word, Excel, PowerPoint
, Publisher, Access, Visio and Project.
Open and create multiple documents in new tabs of the same window, rather than in new windows.
Increases your productivity by
Read More… Free Download… Purchase…
Change Table Style In Word
By default, a table is created with the Table Grid style, which includes a basic black border around each cell in the table. Word includes many built-in styles that provide more visual appeal.
The Table Styles group will show a few table styles, but to see the rest, you’ll need to expand the gallery.
Select a style.
The style is applied to the table, changing the borders, shading, and colors.
You could create a new style by selecting New Table Style or modify an existing one by selecting Modify Table Style and choosing which formatting you’d like.
To remove a Table Style, select Clear from the More Table Styles menu.
You can further customize a table style by changing the table style options.
Use the check boxes in the Table Style Options group to toggle the following settings:
Header Row will apply special formatting to the first row of the table. This special formatting can include font effects, or font, background, and border color.
First Column will apply special formatting to the first column.
Total Row will add special formatting to the final row of a table, designed to summarize the rows above it.
Last Column will apply special formatting to the last column to summarize the earlier columns.
Banded Rows will alternate the background color of rows.
Banded Columns will alternate the background color of columns.
You can control how text is aligned within a table cell, just like you’d align text on the page.
Select the cell or cells you want to align.
You could also select the entire table if you want to align all the text together.
Expand the Alignment group, if necessary.
There are nine alignment options, letting you align the content to either side of a cell, any corner, or center it in the middle of the cell.
Select an alignment option.
The text in the selected cell realigns to the selected side or corner.
You can also select Text Direction to change the text from left-to-right to top-to-bottom or bottom-to-top.
You can also adjust the margins between cell borders and the text within those cells.
Select cell or cells you want to adjust.
You can select the entire table to adjust all the margins at once.
From the Layout tab, expand the Alignment group, if necessary.
In the Table Options dialog box, we can adjust the margins for the selected cell or cells. The margin affects how much space there is between the edge of the cell and the contents of that cell.
Adjust the margins.
You can adjust the margin on each side of the cell independently.
The cell margins are changed.
How To Delete Pivot Table
Pivot tables are useful for sorting, organizing, and summarizing your data in Microsoft Excel. This article explains how to delete a pivot table in Excel 2019, Excel 2016, and Microsoft 365.
How to Delete a Pivot Table in Your Worksheet
Follow these steps to delete both the table itself and the summary created by the table.
Select any cell in your pivot table, then select PivotTable Analyze in the ribbon.
Press the Delete key to delete the pivot table.
How to Delete the Pivot Table and Keep the Data
Follow these steps if you want to delete a pivot table but keep the data within it.
Select any cell in your pivot table, then select PivotTable Analyze in the ribbon.
Highlight the pivot table again and press Delete to remove the table.
How to Delete the Data and Keep the Pivot Table
Once you have the data summary you need, you can clear all of the data so that you can review a new set of data without having to create a new pivot table.
Select any cell in your pivot table, then select PivotTable Analyze in the ribbon.
Bạn đang đọc nội dung bài viết Refresh Pivot Tables Automatically When Source Data Changes trên website Beiqthatgioi.com. Hy vọng một phần nào đó những thông tin mà chúng tôi đã cung cấp là rất hữu ích với bạn. Nếu nội dung bài viết hay, ý nghĩa bạn hãy chia sẻ với bạn bè của mình và luôn theo dõi, ủng hộ chúng tôi để cập nhật những thông tin mới nhất. Chúc bạn một ngày tốt lành!