Fill an array based on userform checkboxes?

largeselection

Active Member
Joined
Aug 4, 2008
Messages
358
Hi,

I have a userform and I would like to update a pivot table based on selected checkboxes.

So I have some code which will edit the pivot table:

Code:
ActiveSheet.PivotTables("Table1").AddFields RowFields:= Array("Name","ID","Age")
 
ActiveSheet.PivotTables("Table1").RowFields("Name").ShowDetail = False
ActiveSHeet.PivotTables("Table1").RowFields("ID").ShowDetail = False

What I'd like to do is create an array to use with this and fill it based on whether a checkbox is selected. So if I have Name, ID, and Age checkboxes, I'd like to be able to select Name and age and then have the array be ("Name", "Age").

Also, I don't know how I could make the ShowDetail = False, since I won't know whether or not a field has been selected. Is it possible to just loop through all the rowfields (except for the last one) and say for each one to set showdetail = false?

Sorry I know that's 2 questions.

Thanks for any insight or ideas.
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi,

This post might give you something to build on. It's similar except the user had ActiveX checkboxes instead of userform checkboxes.

http://www.mrexcel.com/forum/showthread.php?t=519947


Also, I don't know how I could make the ShowDetail = False, since I won't know whether or not a field has been selected. Is it possible to just loop through all the rowfields (except for the last one) and say for each one to set showdetail = false?

This seems trickier than it ought to be. It would be nice to start by setting all PivotItems to False the setting the selected items to True. Unfortunately, Excel doesn't let you set them all to false even temporarily within your procedure.

The example at the link above showed one approach similar to what you suggested.

Hope this helps. :)
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top