VBA to hide column if not hidden and unhide if hidden

oblix

Board Regular
Joined
Mar 29, 2017
Messages
183
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
I would like one button to toggle between hiding a column or unhiding column (columns o to p)
The code should first test the status (hidden/unhidden) and then do the opposite
Code must specifically refer to a sheet in workbook and not current or this worksheet
can anybody help
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi,

maybe you can take this code and adapt it to suit:
VBA Code:
Sub MrE161210B_HideUnhide()
'https://www.mrexcel.com/board/threads/vba-to-hide-column-if-not-hidden-and-unhide-if-hidden.1219441/
  With Workbooks("Copy_files.xlsx").Worksheets("Sheet1").Columns("O:P")
    .Hidden = Not .Hidden
  End With
End Sub
Ciao,
Holger
 
Upvote 0
Solution
Thank you for reply.
Will try this solution
How do I unhide between a range and not unhide all?
 
Upvote 0
How do I unhide between a range and not unhide all?
What exactly do you mean by that, noting that you cannot hide (or unhide) part of a column only (unless you hide/unhide entire rows)?
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

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