+ Reply to Thread
Results 1 to 7 of 7

Macro to unhide a column, and then unhide a second column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-08-2015
    Location
    NJ
    MS-Off Ver
    2013
    Posts
    205

    Macro to unhide a column, and then unhide a second column

    Hello, am working with the attached file where if particular text ("Other" or "Summer") is input in either column B or D, the column to the right ("C" or "E") are unhidden. One more step is needed where if additional text is input into column "C" or "E", that column needs to remain unhidden. It currently hides after typing new text.

    Any suggestions?

    Thanks so much.
    Sheryl
    Attached Files Attached Files

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,441

    Re: Macro to unhide a column, and then unhide a second column

    .
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Target.Column = 2 And Target.Value = "Other" And Application.Columns("C").Hidden = True Then
            Application.Columns("C").EntireColumn.Hidden = False
        ElseIf Target.Column = 4 And Target.Value = "Summer" And Application.Columns("E").Hidden = True Then
            Application.Columns("E").EntireColumn.Hidden = False
        Else
            Exit Sub
        End If
        
    End Sub
    As before, paste in to the Sheet Level Module

  3. #3
    Forum Contributor
    Join Date
    08-08-2015
    Location
    NJ
    MS-Off Ver
    2013
    Posts
    205

    Re: Macro to unhide a column, and then unhide a second column

    Hi, thanks again for the quick response. This does not seem to be working, perhaps I am doing something incorrect with pasting the code. I pasted after the first set of code in the Sheet1 and the second set of columns "C" and "E" are still hiding after typing any text within those columns. Any suggestions?

    Thank you again.
    Sheryl

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

    Re: Macro to unhide a column, and then unhide a second column

    Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in column B or D.
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("B:B,D:D")) Is Nothing Then Exit Sub
        Select Case Target.Column
            Case Is = 2
                If Target = "Other" Then
                    Columns("C").EntireColumn.Hidden = True
                Else
                    Columns("C").EntireColumn.Hidden = False
                End If
            Case Is = 4
                If Target = "Summer" Then
                    Columns("E").EntireColumn.Hidden = True
                Else
                    Columns("E").EntireColumn.Hidden = False
                End If
        End Select
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  5. #5
    Forum Contributor
    Join Date
    08-08-2015
    Location
    NJ
    MS-Off Ver
    2013
    Posts
    205
    Quote Originally Posted by Mumps1 View Post
    Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in column B or D.
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("B:B,D:D")) Is Nothing Then Exit Sub
        Select Case Target.Column
            Case Is = 2
                If Target = "Other" Then
                    Columns("C").EntireColumn.Hidden = True
                Else
                    Columns("C").EntireColumn.Hidden = False
                End If
            Case Is = 4
                If Target = "Summer" Then
                    Columns("E").EntireColumn.Hidden = True
                Else
                    Columns("E").EntireColumn.Hidden = False
                End If
        End Select
    End Sub
    THANK YOU, this is perfect !

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

    Re: Macro to unhide a column, and then unhide a second column

    You are very welcome.

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,441

    Re: Macro to unhide a column, and then unhide a second column

    .
    Make certain you remove the previous code from your other post. With the Sheet Level Module empty, paste the code above from Post #2
    in the Sheet Level Module. Say ... for Sheet 1, right click the Sheet1 tab and select VIEW CODE. Paste the macro code.

    When you choose OTHER or SUMMER in the respective columns, the adjoining column becomes unhidden and remains so.

    I tried Mumps1 macro here and find it works opposite of what you were seeking. Confusing.

+ 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] Macro to unhide & hide rows based on column value
    By qvfr034 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-15-2020, 03:00 PM
  2. [SOLVED] Macro for Hide & Unhide the rows upto a certain column
    By Neilesh Kumar in forum Excel General
    Replies: 11
    Last Post: 09-14-2017, 10:08 AM
  3. Macro to unhide a row and a column
    By bluelillies in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2017, 09:59 PM
  4. [SOLVED] VBA macro that hide and unhide column to respective rows based on first column value
    By janine6192 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2013, 06:21 PM
  5. column hide/unhide macro
    By chiz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2008, 11:05 AM
  6. Check Box Macro to hide and unhide a column
    By Daphne in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-26-2006, 08:55 AM
  7. How do I unhide a column when format/column/unhide won't work
    By lincolnblaze in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-13-2005, 11:45 PM

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