Sign up for our Excel webinar, times added weekly: https://www.excelcampus.com/blueprint-registration/
In this video I explain how to use macro buttons to add or remove fields to your pivot tables. This is great for reports and dashboards where you want to allow users to quickly see different views of the data. The users don't have to be familiar with how to modify pivot tables.
Download the Excel file and read the post: https://www.excelcampus.com/vba/macro-buttons-pivot-table-fields/
I share two VBA macros in this video.
The first macro will remove all fields from the Rows area of the pivot table, then add the field based on the macro button that was pressed.
The second macro is a toggle that allows the user to add or remove each field independently. This allows the user to add multiple fields to the pivot table, and control the order of the fields in the Rows or Columns area.
The macro uses the Application.Caller property to retrieve the text from the button, and use it in the code. This means we can use the same macro for all of the buttons on the sheet.
I also explain how to create additional buttons in the video.
You can still use Slicers and Pivot Charts with the pivot tables. The macro buttons just automate the process of changing the fields in the pivot table.
Related videos & articles:
Intro to Pivot Tables & Dashboards - https://youtu.be/9NUjHBNWe9M
Intro to Macros & VBA -https://www.excelcampus.com/vba/macros-explained-part-1/
Automatic Number Formatting for Pivot Tables - https://youtu.be/xW5tlzSdx-A
Filter Non-Pivot Table Columns with a Slicer- https://www.excelcampus.com/vba/hide-unhide-columns-slicer-filter/
Refresh Pivot Tables Automatically - https://youtu.be/NI1UQcYtl1A
00:00 Introduction
00:11 Adding Macro Buttons to a Pivot Table
01:06 Macro to Replace Fields in the Rows Area
04:09 Copy & Align