AndrosoSabroso
New Member
- Joined
- Oct 8, 2023
- Messages
- 2
- Office Version
- 2013
- Platform
- Windows
Hi! Thanks for checking this thread
I am new to VBA and I am working on a project to create an interactive dashboard for the finantial statements of the company, spanning a couple decades of data.
I have already figured out the slicer part of the dashboard to filter dates, however, I have not been able to get a working macro for toggling on and off a data value field.
The formula I am using is the following:
Sub DataField()
If ActiveSheet.PivotTables("Test").PivotFields("Sum of Example").Orientation.Value = xlHidden Then
ActiveSheet.PivotTables("Test").AddDataField ActiveSheet.PivotTables("Test").PivotFields("Example")
Else
ActiveSheet.PivotTables("Test").PivotFields("Sum of Example").Orientation = xlHidden
End If
End Sub
The goal is to create a button with a macro able to detect wether or not the "Example" field within the "Test" pivot table is currently added as a data value field.
If it is added, then the macro should remove it, if it is not added, then the macro should add it.
Also, if there was some sort of way to make the fields name a dynamic refference tied to the buttons name, that would be fantastic! That would allow me to use the same macro for the toggling of all fields, only by changing button names.
I just got started with VBA. Any feedback is very much appreciated.
Thank you so much for your help!
I am new to VBA and I am working on a project to create an interactive dashboard for the finantial statements of the company, spanning a couple decades of data.
I have already figured out the slicer part of the dashboard to filter dates, however, I have not been able to get a working macro for toggling on and off a data value field.
The formula I am using is the following:
Sub DataField()
If ActiveSheet.PivotTables("Test").PivotFields("Sum of Example").Orientation.Value = xlHidden Then
ActiveSheet.PivotTables("Test").AddDataField ActiveSheet.PivotTables("Test").PivotFields("Example")
Else
ActiveSheet.PivotTables("Test").PivotFields("Sum of Example").Orientation = xlHidden
End If
End Sub
The goal is to create a button with a macro able to detect wether or not the "Example" field within the "Test" pivot table is currently added as a data value field.
If it is added, then the macro should remove it, if it is not added, then the macro should add it.
Also, if there was some sort of way to make the fields name a dynamic refference tied to the buttons name, that would be fantastic! That would allow me to use the same macro for the toggling of all fields, only by changing button names.
I just got started with VBA. Any feedback is very much appreciated.
Thank you so much for your help!