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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,552
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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.
 

GregM

New Member
Joined
Jan 15, 2005
Messages
14
Works like a charm -- thank you very much for your assistance.
Have a great day!
 

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,552
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
You are welcome. Thanks for the feedback.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,713
Messages
5,833,269
Members
430,200
Latest member
ADLHMA2022

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
Top