HELP VBA code for auto hiding a certain Column in every tab

usui

New Member
Joined
Apr 20, 2020
Messages
9
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi masters,


I would like to ask a help regarding vba code that can auto hide a certain column in each tab..for example Column C1 = I want to hide all that is under C1..

so basically i have a certain name in row1 that i want to auto hide in each tab
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
46,235
Office Version
  1. 365
Platform
  1. Windows
See if you can use something like this. Test with a copy of your workbook.

VBA Code:
Sub Hide_Cols()
  Dim ws As Worksheet
  Dim c As Long
  
  For Each ws In Worksheets
    With ws
      For c = 1 To .Cells(1, Columns.Count).End(xlToLeft).Column
        If .Cells(1, c).Value = "abc" Then '<- edit this to your name of interest
          .Columns(c).Hidden = True
        End If
      Next c
    End With
  Next ws
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,004
Messages
5,526,228
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top