+ Reply to Thread
Results 1 to 7 of 7

Question on my code: simple hide/unhide rows

  1. #1
    Registered User
    Join Date
    05-17-2021
    Location
    UK
    MS-Off Ver
    2016 / O365
    Posts
    4

    Question on my code: simple hide/unhide rows

    Hello,
    My macro works fine for the most part! Just need a small tweak, if somebody could be kind enough to take a look.
    Cell A31 has the following four drop-down selections:
    - Up to 5
    - 6 to 10
    - 11 to 20
    - Over 20

    Selecting 'Up to 5': Rows 37-41 will unhide
    Selecting '6 to 10': Rows 37-46 will unhide
    Selecting '11 to 20': Rows 37-56 will unhide
    Selecting 'Over 20': Rows 37-64 will unhide

    So my starting point is that rows 37-64 are hidden, and the appropriate number of rows will unhide based on a user selection.
    The code I am using is below, and it works fine for unhiding.
    The problem is that it won't dynamically update. E.g. if a user first selects '6 to 10', the required rows 37-46 will unhide fine. However if the user then changes the selection to 'up to 5', Excel won't revert to only showing rows 37-41.

    This is my code:

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 06-01-2021 at 06:47 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,525

    Re: Question on my code: simple hide/unhide rows

    Try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,535

    Re: Question on my code: simple hide/unhide rows

    Put an extra line in to hide from 37 to 64 and after unhide the rows as needed.

    BTW, read the Forum Rules, at the top, and act on #2.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Question on my code: simple hide/unhide rows

    You unhide rows but you never re-hide the ones that should be hidden.

    Also, you don't have to do this every time anything changes on the sheet. You just need to check whether A31 changed.

    Try this:

    Please Login or Register  to view this content.
    By the way, it looks like 37-41 are always unhidden. Does some other process hide them?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,535

    Re: Question on my code: simple hide/unhide rows

    With Select Case. Might be easier to maintain/add to/change.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-17-2021
    Location
    UK
    MS-Off Ver
    2016 / O365
    Posts
    4

    Re: Question on my code: simple hide/unhide rows

    thanks every body, resolved! And sorry for forgetting rule #2, newbie here

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,525

    Re: Question on my code: simple hide/unhide rows

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] vba code to hide and unhide rows one by one
    By bluepomme in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2019, 06:23 PM
  2. [SOLVED] VBA code to hide/unhide rows on 2 different sheets-HELP
    By bugdout in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2017, 04:03 PM
  3. toggle hide unhide rows, vba code
    By annazet in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-18-2017, 03:06 PM
  4. need code to hide/unhide rows
    By mariobross106 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-30-2015, 09:27 PM
  5. simple macro to hide or unhide rows based on a cell value
    By Russ Fuquay in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2013, 06:32 PM
  6. Code to Hide and Unhide Rows
    By jcoulter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-13-2012, 10:38 AM
  7. Hide/Unhide Rows VBA code Changes Help
    By Justinmih in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-12-2011, 04:24 PM

Tags for this Thread

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