Hide and Show Columns in Pivot Table (Excel 2010)

gabnash

New Member
Joined
Apr 24, 2014
Messages
2
I have a pivot table that has 11 columns. I'd like it to become a table where only 8 columns are visible. The user can press a button and the first three columns toggle with three columns that are initially hidden. Pressing the button a second time should revert back to the initial state.

I managed to write piece of VBA code to hide three columns - but I couldn't get them back again!

Any help gratefully received!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Supposing you want to toggle the hidden property of columns A to C, you could use the following code. If the columns are hidden then the macro will unhide them. Conversely, if the columns are unhidden then the macro will hide them.

(You could also assign this macro to a form control button, which users can click to toggle the hidden property.)

Code:
Sub ToggleHidden()
    With Columns("A:C")
        .Hidden = Not .Hidden
    End With
End Sub
 
Upvote 0
Many thanks for your help. I managed to implement the toggling action I wanted by adding one more line of code to yours.


Code:
Sub Toggle()

      With Columns("C:E")
            .Hidden = Not .Hidden
      End With

     Columns("F:H").Hidden = Not Columns("C:E").Hidden   

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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