Consulting

Results 1 to 5 of 5

Thread: Conditionally hide and unhide cell ranges

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Conditionally hide and unhide cell ranges

    I need to conditionally hide and unhide ranges of cells based on a certain condition. I know it goes in the worksheet change event.

    Found this code that does rows, but how do you alter it to do say C1:C15 and F1:F15 if the condition is met?

    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$C$14" Then
    If Target.Value = 1 Then
    Rows(10).EntireRow.Hidden = True
    Else
    Rows(10).EntireRow.Hidden = False
    End If
    End If
    End Sub[/VBA]
    Peace of mind is found in some of the strangest places.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can't hide individual cells, it is entire rows/columns, or nothing.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    I was afraid of that Bob. I have borders around cells that if the rows are hidden, the remaining will look bloody awful.
    Peace of mind is found in some of the strangest places.

  4. #4
    Try this code

    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Set rng = Union(Range("C1:C15"), Range("F1:F15"))
    If Not Intersect(Target, rng) Is Nothing Then
    If Target.Value = 1 Then
    Rows(10).EntireRow.Hidden = True
    Else
    Rows(10).EntireRow.Hidden = False
    End If
    End If
    End Sub
    [/VBA]

  5. #5
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    May be able to use the first code after all. how do you do multiple rows?
    Peace of mind is found in some of the strangest places.

Posting Permissions

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