+ Reply to Thread
Results 1 to 10 of 10

unhide or hide rows depending on previous row value

  1. #1
    Forum Contributor
    Join Date
    11-22-2006
    MS-Off Ver
    2010
    Posts
    201

    unhide or hide rows depending on previous row value

    good morning everyone.

    can anyone help with this query?

    I have a range in rows 4 to 13 in a spreadsheet.

    Column B in this range can either be blank or have a value selected from a validation list.

    What i would really like to do is, if B4 is left blank then rows 5 to 13 are hidden, if B4 is given a value from the validation list, then row 5 unhides, if B5 is completed then row 6 unhides etc.

    Hope that is possible.
    thanks

    Lucy

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: unhide or hide rows depending on previous row value

    Try this

    In the worksheet module (Right click Tab .> view code)

    Paste
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    11-22-2006
    MS-Off Ver
    2010
    Posts
    201

    Re: unhide or hide rows depending on previous row value

    thanks Marcol, that works for cell B4, and hides the rest of the section.
    if i then decide that B5 is to be blank, then how do i get rows 6 to 15 to be hidden ?
    I tried adapting the code like this, but it gets into a loop (i think) and everything remains unhidden.
    Thanks for your help.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("B4") = "" Then
    Rows("5:15").Hidden = True
    If Range("B5") = "" Then
    Rows("6:15").Hidden = True
    If Range("B6") = "" Then
    Rows("7:15").Hidden = True
    If Range("B7") = "" Then
    Rows("8:15").Hidden = True
    If Range("B8") = "" Then
    Rows("9:15").Hidden = True
    If Range("B9") = "" Then
    Rows("10:15").Hidden = True
    If Range("B10") = "" Then
    Rows("11:15").Hidden = True
    If Range("B11") = "" Then
    Rows("12:15").Hidden = True
    If Range("B12") = "" Then
    Rows("13:15").Hidden = True
    Else
    Rows("5:15").Hidden = False
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End Sub

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: unhide or hide rows depending on previous row value

    Will you ever leave a blank cell in B4:B15?

    e.g. B4:B10 filled, B11 blank, B12:B15 filled.

    Tip

    Wrap code with the code tags #, not Quotes
    Last edited by Marcol; 04-19-2010 at 05:33 AM.

  5. #5
    Forum Contributor
    Join Date
    11-22-2006
    MS-Off Ver
    2010
    Posts
    201

    Re: unhide or hide rows depending on previous row value

    Hi Marcol, yes there may be instances when someone would leave a blank somewhere in the range with values above and below it.

    Thanks

    Lucy

  6. #6
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: unhide or hide rows depending on previous row value

    Hi.
    In your active sheet, try this code:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-22-2006
    MS-Off Ver
    2010
    Posts
    201

    Re: unhide or hide rows depending on previous row value

    Thanks Wamp, that is very useful.

    Best wishes
    Lucy

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: unhide or hide rows depending on previous row value

    Sorry a bit late

    Try this
    Please Login or Register  to view this content.

    This should allow multiple deletion, and fill_down in column B

    Cheers

  9. #9
    Forum Contributor
    Join Date
    11-22-2006
    MS-Off Ver
    2010
    Posts
    201

    Re: unhide or hide rows depending on previous row value

    thanks Marcol, i really appreciate you taking the time to work it out and post on the forum.

    Lucy

  10. #10
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: unhide or hide rows depending on previous row value

    Always happy to help.

    If you need any further information, please feel free to ask further

    However

    If this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of thier post to show your appreciation.

+ 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