Macro For Hiding Column

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
Thanks for looking at my post.
I have the code below for hiding a column in my workbook. I was wanting to see if the code could be made so it would hide column A on any sheet. I have 21 sheets in the workbook

Code:
Sub Hide_Column()
ActiveSheet.Unprotect
If Sheets("Sht#1").Range("A").EntireColumn.Hidden = False Then
    Sheets("Sht#1").Range("A").EntireColumn.Hidden = True
Else
    Sheets("Sht#1").Range("A").EntireColumn.Hidden = False
End If
ActiveSheet.Protect
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
This will work on any active sheet:
Code:
Sub Hide_Column()
    ActiveSheet.Unprotect
    If ActiveSheet.Range("A").EntireColumn.Hidden = False Then
        ActiveSheet.Range("A").EntireColumn.Hidden = True
    Else
        ActiveSheet.Range("A").EntireColumn.Hidden = False
    End If
    ActiveSheet.Protect
End Sub
or did you mean that you wanted it to work on all 21 sheets at the same time?
 
Upvote 0
Try:
Code:
Sub Hide_Column()
Dim Sht As Worksheet
For Each Sht In Worksheets
    Sht.Columns("A").Hidden = Not Sht.Columns("A").Hidden
Next Sht
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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