+ Reply to Thread
Results 1 to 6 of 6

Macro to hide multiple columns

Hybrid View

  1. #1
    Registered User
    Join Date
    01-09-2013
    Location
    Arlington, Texas
    MS-Off Ver
    Excel 2010
    Posts
    3

    Macro to hide multiple columns

    I need help creating a macro to hide and unhide several non-adjacent columns based on a value in cell D2.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,097

    Re: Macro to hide multiple columns

    Which columns do you want to hide or unhide and what value in D2 determines whether to hide or unhide?

  3. #3
    Registered User
    Join Date
    01-09-2013
    Location
    Arlington, Texas
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to hide multiple columns

    Cell D2 will contain a label, either "City" or "State". If the value is "City", I want columns Q, R, & S to be hidden. If the value is "State", I want columns Z, AA, and AB to be hidden.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to hide multiple columns

    Maybe:

    Sub MistiM()
    
    Select Case Range("D2").Value
    
        Case Is = "City"
        
            Columns("Q:S").Hidden = True
            Columns("Z:AB").Hidden = False
            
        Case Is = "State"
        
            Columns("Z:AB").Hidden = True
            Columns("Q:S").Hidden = False
            
    End Select
    End Sub

  5. #5
    Registered User
    Join Date
    01-09-2013
    Location
    Arlington, Texas
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to hide multiple columns

    This works perfectly. Thank you so much!

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to hide multiple columns

    You're welcome. Glad to help out, and thanks for the feedback. Please comply with Forum Rule No. 9.

    9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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