+ Reply to Thread
Results 1 to 9 of 9

Dropdown to hide/show rows

  1. #1
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    122

    Dropdown to hide/show rows

    I have a cell that is using data validation using the numbers 1-15, based on the number in that box i want to show that number of rows, the default is 1 so lets say row will be visable, if the drop down changes to say 3, rows 3,4, and 5 will be visable. The closest i have gotten is autofilter but does not show the rows, just a row at a time. I dont want the dropdown to add rows, just hide/unhide them based on the dropdown number. Is this possible?
    Last edited by paxile2k; 07-27-2009 at 04:29 PM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Dropdown to hide/show rows

    dont quite follow if in your example 15 was chosen do you want to show 1-15 or 15-29. cant see the logic of 3 show 3-5
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Dropdown to hide/show rows

    Thankyou for your response,

    I have cell A2 setup to use a drop down with the numbers 1-15, i would like that drop to hide/show rows 3-17, if the drop down is changed to 3, rows 3,4 and 5 will be visable and the others hidden, if the drop down is changed to 7, rows 3-10 will be visable and the others below it will be hidden. I was using 3 as an example as what is chosen from the dropdown menu.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dropdown to hide/show rows

    Try this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Dropdown to hide/show rows

    thankyou for your response,

    Thankyou for the code, i tweaked a little bit, only issue is that with the number 2 being chosen it should show 2 rows but it only hows the same as if 1 were chosen.

    Here is the code i am using from your example:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Long
    If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("A2")) Is Nothing Then
    Rows("4:17").Hidden = True
    For i = 1 To Range("A2").Value
    Rows(i + 1).Hidden = False
    Next i
    End If
    End Sub

    Correction: everything is offset by 1, if you select 1, nothing appears, if you select 2, one row appears, if you select 3, 2 rows appear, and so on
    Last edited by paxile2k; 07-27-2009 at 04:04 PM.

  6. #6
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Dropdown to hide/show rows

    Nevermind i adjusted it incorrectly, thankyou verymuch for your assistance It was greatly appreciated

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dropdown to hide/show rows

    Can you please edit your post #5 above to wrap the code in [code] tags as per forum rules? Or just delete the code.

    Thanks.

  8. #8
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Dropdown to hide/show rows

    Is there a way to have two of these options in one spreadsheet? I have spreadsheet where it is working fine, but i am trying to add another hide a different set of rows? Does the code need a different name?

    Example of code:
    Please Login or Register  to view this content.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dropdown to hide/show rows

    I know it looks like your question is related, but it's actually a completely different topic. Forum rules make posting add-on questions in someone else's thread a no-no...so remember that next time, OK.

    Just start your own thread and include links to other threads you "think" might be relevant.

    In this instance, your own question is simply: "Can you have more than one Worksheet_Change macro in one sheet?" If you Googled that question, you'd find immediately the answer is no.

    But you can make the one ws_change event do multiple things.
    Please Login or Register  to view this content.

+ 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