简体   繁体   中英

How to hide the columns in excel sheet based on column name condition

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM