+ Reply to Thread
Results 1 to 3 of 3

Hide and unhide columns

  1. #1
    Frederic
    Guest

    Hide and unhide columns

    I have the following statement. Instead of hiding and unhiding the range
    "B:J", I want to hide and unhide Columns "B,D,f,H"

    Please find below the statement I have used. Any advise would be very much
    appreciated.


    Private Sub CommandButton1_Click()
    Macro2
    End Sub

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim arr As Variant

    arr = Array("EO", "EC", "ES", "EV", "EF", "EG")
    If Target.Cells.Count > 1 Then Exit Sub

    If Target.Column = 1 Then
    Columns("B:J").EntireColumn.Hidden = _
    IsError(Application.Match(Target.Value, arr, 0))
    End If

    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Union(Range("A:A"), Range("B:J"))) Is Nothing Then
    Columns("B:J").EntireColumn.Hidden = True
    End If
    End Sub


  2. #2
    Wolf
    Guest

    RE: Hide and unhide columns

    Columns("B:B,D:D,F:F,H:H").EntireColumn.Hidden.......etc

    (BTW: The macro recorder could have told you the same)

    Wolf

    "Frederic" wrote:

    > I have the following statement. Instead of hiding and unhiding the range
    > "B:J", I want to hide and unhide Columns "B,D,f,H"
    >
    > Please find below the statement I have used. Any advise would be very much
    > appreciated.
    >
    >
    > Private Sub CommandButton1_Click()
    > Macro2
    > End Sub
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim arr As Variant
    >
    > arr = Array("EO", "EC", "ES", "EV", "EF", "EG")
    > If Target.Cells.Count > 1 Then Exit Sub
    >
    > If Target.Column = 1 Then
    > Columns("B:J").EntireColumn.Hidden = _
    > IsError(Application.Match(Target.Value, arr, 0))
    > End If
    >
    > End Sub
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > If Intersect(Target, Union(Range("A:A"), Range("B:J"))) Is Nothing Then
    > Columns("B:J").EntireColumn.Hidden = True
    > End If
    > End Sub
    >


  3. #3
    Norman Jones
    Guest

    Re: Hide and unhide columns

    Hi Frederick,

    Try:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim arr As Variant
    Dim rng As Range

    Set rng = Range("B1, D1, F1, H1")

    arr = Array("EO", "EC", "ES", "EV", "EF", "EG")
    If Target.Cells.Count > 1 Then Exit Sub

    If Target.Column = 1 Then
    rng.EntireColumn.Hidden = _
    IsError(Application.Match(Target.Value, arr, 0))
    End If

    End Sub


    ---
    Regards,
    Norman



    "Frederic" <[email protected]> wrote in message
    news:[email protected]...
    >I have the following statement. Instead of hiding and unhiding the range
    > "B:J", I want to hide and unhide Columns "B,D,f,H"
    >
    > Please find below the statement I have used. Any advise would be very much
    > appreciated.
    >
    >
    > Private Sub CommandButton1_Click()
    > Macro2
    > End Sub
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim arr As Variant
    >
    > arr = Array("EO", "EC", "ES", "EV", "EF", "EG")
    > If Target.Cells.Count > 1 Then Exit Sub
    >
    > If Target.Column = 1 Then
    > Columns("B:J").EntireColumn.Hidden = _
    > IsError(Application.Match(Target.Value, arr, 0))
    > End If
    >
    > End Sub
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > If Intersect(Target, Union(Range("A:A"), Range("B:J"))) Is Nothing Then
    > Columns("B:J").EntireColumn.Hidden = True
    > 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)

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