+ Reply to Thread
Results 1 to 4 of 4

VBA to hide Multiple Columns based on Headers

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-22-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016-2019, LTSC Pro Plus 2021, Office365
    Posts
    153

    VBA to hide Multiple Columns based on Headers

    Hello Forumreaders,

    Can someone help me with a code that hide every columns that does not confirm to the cell value in a row 5 for example.
    I have a code that deletes all columns, but I have to hide these columns and not delete them.

    With regards,
    FvdF


    Public Sub DeleteColumns()
        Dim Counter As Long
        
        Application.ScreenUpdating = False
        
        For Counter = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
            Select Case Cells(5, Counter).Value
                Case "1"
                Case "LBO1"
                Case "LDN1"
                Case "GHI1"
                Case "HAA1"
                Case "IJC1"
                Case "KEN1"
                Case "ZAA1"
                Case "WAT1"
                Case Else
                    ActiveSheet.Columns(Counter).Delete
            End Select
        Next Counter
        
    End Sub
    Last edited by FvdF; 06-28-2020 at 05:06 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: VBA to hide Multiple Columns based on Headers

    Try this...
    Sub test()
    Dim Crit, Counter As Long
    Crit = Array("1", "LBO1", "LDN1", "GHI1", "HAA1", "IJC1", "KEN1", "ZAA1", "WAT1")
    For Counter = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
        If Not IsNumeric(Application.Match(Cells(5, Counter), Crit, 0)) Then Columns(Counter).EntireColumn.Hidden = True
    Next Counter
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    03-22-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016-2019, LTSC Pro Plus 2021, Office365
    Posts
    153

    Re: VBA to hide Multiple Columns based on Headers

    Thanks, this works for me now.

    Grtz,
    FvdF

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: VBA to hide Multiple Columns based on Headers

    Pleasure...Tx for adding rep...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extract multiple row headers and column headers if criteria is met in multiple columns
    By PaulM100 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 09-20-2019, 04:56 AM
  2. [SOLVED] Hide same columns that were hidden for the other headers
    By luajambeiro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-19-2019, 10:57 AM
  3. [SOLVED] Match and copy multiple columns based on different headers
    By Flor87 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-20-2019, 08:35 AM
  4. Copy/Paste Columns from Multiple Worksheets based on Headers into new Worksheet
    By casper3043 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2015, 03:06 PM
  5. [SOLVED] Hide all columns except those with certain headers/titles
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-31-2014, 08:32 AM
  6. Selecting Multiple columns based on headers and copying to seaperate sheet
    By jonto81 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-03-2013, 10:44 AM
  7. [SOLVED] Hide columns based on dynamic headers
    By pdalal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2013, 03:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1