0
votes

I have an Excel workbook where I have multiple number of sheets. I want to hide some of the columns in all the sheets where headers starting with a string "AUDIT_".

I am trying to find out a simple solution to hide these columns in all the sheets so that I don't need to go every sheet and click hide.

Can you please suggest me on this.

1
Write a VBA macro to loop through the sheets, check the column name aginst your condition and hide. You can use the "Record Macro" function and perform the steps by hand once to get some VBA code generated to get you started (Access the Macros using ALT + F11)baarkerlounger

1 Answers

1
votes

Give this a try:

Sub ColumnHider()
    Dim s As Worksheet, N As Long, i As Long
    For Each s In Worksheets
        s.Activate
        N = Cells(1, Columns.Count).End(xlToLeft).Column
        For i = 1 To N
            If Left(Cells(1, i).Value, 6) = "AUDIT_" Then
                Cells(1, i).EntireColumn.Hidden = True
            End If
        Next i
    Next s
End Sub