+ Reply to Thread
Results 1 to 9 of 9

Hiding rows based on cell result

Hybrid View

  1. #1
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi again,

    Adjust the following to your situation ...
    Private Sub Worksheet_Change(ByVal Target As Range)
    Set Target = Range("A1") '<-------------------adjust to your needs
    If Target.Value = "No" Then
    Target.Offset(6, 0).EntireRow.Hidden = True  '<--adjust 6 to your needs
    ElseIf Target.Value = "Yes" Then
    Target.Offset(6, 0).EntireRow.Hidden = False '<--adjust 6 to your needs
    End If
    End Sub
    HTH
    Carim

  2. #2
    Registered User
    Join Date
    10-02-2003
    Location
    East Midlands, UK
    MS-Off Ver
    MS Office Professional Plus 2016
    Posts
    40
    Thanks for that - it's great!

    How about if I wish to hide more than one consecutive row? Would that just require me to change the Target.Offset e.g., if I wanted to hid three rows, would I put (6, 3), (6,9) or something else?

    Cheers,

    Baldy

  3. #3
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Private Sub Worksheet_Change(ByVal Target As Range)
    Set Target = Range("A1")
    If Target.Value = "No" Then
    Target.Offset(3, 0).EntireRow.Hidden = True
    Target.Offset(6, 0).EntireRow.Hidden = True
    Target.Offset(9, 0).EntireRow.Hidden = True
    ElseIf Target.Value = "Yes" Then
    Target.Offset(3, 0).EntireRow.Hidden = False
    Target.Offset(6, 0).EntireRow.Hidden = False
    Target.Offset(9, 0).EntireRow.Hidden = False
    End If
    End Sub
    HTH
    Carim

  4. #4
    Registered User
    Join Date
    10-02-2003
    Location
    East Midlands, UK
    MS-Off Ver
    MS Office Professional Plus 2016
    Posts
    40
    Where 3,6 & 9 are just the relative distance from the target row, yes?

    And - sorry to be a nuisance - if I need to have more than one of these things on the same worksheet, how do I do that? I tried pasting the thing and renaming the subroutine to Worksheet_Change2 and also changing the variable name target to target2, but no luck...

  5. #5
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Yes ... the offset() function, to use your terminology, works with "relative distance" ....

    You can have many worksheets events with different events ... but for a given event you can only have one of each ...
    Solution : code all your requirements within that particular one ...

    HTH
    Carim

  6. #6
    Registered User
    Join Date
    10-02-2003
    Location
    East Midlands, UK
    MS-Off Ver
    MS Office Professional Plus 2016
    Posts
    40
    Lovely - thanks for all your help!

  7. #7
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    You are welcome ...

    Thanks for the feedback

    Carim

+ 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