+ Reply to Thread
Results 1 to 3 of 3

Hide Columns with Drop Down list

Hybrid View

  1. #1
    Registered User
    Join Date
    12-12-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Hide Columns with Drop Down list

    I want to write a macro that will hide columns base on a drop down list. My drop down is located in Cell A3 and contains 6 names. These names are located in each column (C through the end of the worksheet) in row2 (C2 to ???2). The names appear in random order. When I select a particular name from the drop down I want the macro to hide the other 5 names not selected.

    So far I've got

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Range("A3"), Target) Is Nothing Then
    Columns("c:k").EntireColumn.Hidden = False
    Select Case Target.Value
    
    Case "Name 1":
    
    End Select
    End If
    End Sub
    But I can't figure out how to write the case to hide the columns I want hidden

    Moderator's Edit: Use code tags when posting code. To do so in future, select your code and click on the # icon above.
    Last edited by arlu1201; 12-12-2012 at 03:12 PM.

  2. #2
    Registered User
    Join Date
    12-12-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Hide Columns with Drop Down list

    I want to write a macro that will hide columns base on a drop down list. My drop down is located in Cell A3 and contains 6 names. These names are located in each column (C through the end of the worksheet) in row2 (C2 to ???2). The names appear in random order. When I select a particular name from the drop down I want the macro to hide the other 5 names not selected.

    So far I've got

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Range("A3"), Target) Is Nothing Then
    Columns("c:k").EntireColumn.Hidden = False
    Select Case Target.Value
    
    Case "Name 1":
    
    End Select
    End If
    End Sub
    But I can't figure out how to write the case to hide the columns I want hidden

  3. #3
    Registered User
    Join Date
    09-24-2012
    Location
    California
    MS-Off Ver
    Office 2010
    Posts
    33

    Re: Hide Columns with Drop Down list

    I obviously don't know what range goes with which case, but here is how I would do it w/ kind of random conditions:

     
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$A$3" Then
        Range("C:K").EntireColumn.Hidden = False
            If Target = "Name 1" Then
               Range("C").EntireColumn.Hidden = True
            ElseIf Target = "Name 2" Then
                Range("C:E,H:J").EntireColumn.Hidden = True
            End If
        End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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