Buttons to HIDE / UNHIDE columns

GregM

New Member
Joined
Jan 15, 2005
Messages
14
Hello friends. I have put together the following by reading several similar threads. I am putting two buttons at the top of a spreadsheet, one to display the first group and hide the second and vice-versa. If possible, I guess it'd be better to use one button to toggle these changes. I figured out how to insert the code and attach it to the button, I just need help in writing this code EXACTLY as it should be to put it in a module.

Two buttons: 1) Select columns("O:U") .Hidden = False, Select columns("V:AK") .Hidden = True
2) Select columns("O:U") .Hidden = True, Select columns("V:AK") .Hidden = False

Thanks to all!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
GregM,


Here is one way that will toggle.

Code:
Sub Toggle_Cols()
Range("O1:U1").EntireColumn.Hidden = Range("V1:AK1").EntireColumn.Hidden
Range("V1:AK1").EntireColumn.Hidden = Not Range("O1:U1").EntireColumn.Hidden
End Sub

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,222,900
Messages
6,168,926
Members
452,227
Latest member
sam1121

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