Button to Hide and Unhide columns? - I am using a Mac

russelldt

Board Regular
Joined
Feb 27, 2021
Messages
160
Office Version
  1. 365
Platform
  1. MacOS
Hello,

I have searched for a solution to the question I have asked, but can't find any that work for me. Either because I am running 365 on the Mac platform, or I just plain dumb (or both).

I have 2 sets on columns D to G and J to M. each independent of one another.

I need a button to Hide D to G, and then when I press it again to Unhide the same columns.

There will be another button for columns J to M that functions the same way.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about
VBA Code:
Sub rselldt()
   With Range("D:G").EntireColumn
      .Hidden = Not .Hidden
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
No they won't be. You would need to loop through all the checkboxes & see where they are located & then hide/unhide them.
 
Upvote 0
I missed the most important aspect in my brief

Many cells In the columns are locked, so the sheet is protected. I would like to unprotect the sheet, I unhide the columns and then protect the sheet again - in the same VBA.

Thank you
 
Upvote 0
How about
VBA Code:
Sub russelldt()
   With Sheets("Sheet1")
      .Unprotect "Pword"
      With .Range("D:G").EntireColumn
         .Hidden = Not .Hidden
      End With
      .Protect "Pword"
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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