+ Reply to Thread
Results 1 to 12 of 12

Automatically hide/unhide rows based on cell value

  1. #1
    Registered User
    Join Date
    07-28-2014
    Location
    Perth, Australia
    MS-Off Ver
    2019
    Posts
    31

    Automatically hide/unhide rows based on cell value

    Hello everyone, I am not positive that this is the right section to post in, or that VBA is even the right/best way to go with solving this problem, but I'll give it a try.

    I am wondering if it is possible to write in staff names (up to 80) on Staff!, but have the rows 23-80 hidden and only unhide row 23 when a staff name is typed into cell A22. Row 24 would unhide when there is a staff name typed in cell A23, and so on for all the rows 23-80. When this happens on Staff! sheet, it should also do the same thing in all the other sheets (Jan-Mar, Apr-June, July-Sept, Oct-Dec) and triggered by what happens with the staff names on the Staff! sheet.

    The Staff! sheet has the calendar on it (which is why I can't hide the entire row until row 23 as it would hide part of the calendar), but on all the other sheets there is nothing hindering all the rows from being hidden until the previous row has a staff name in it. Is it possible to do this?

    I am hoping for all this to be automatic without needing any operator input (like buttons or refreshing or filtering), but to have a code or something running all the time to watch what happens with the staff names and then trigger the hiding or unhiding.

    Please find example document attached.

    Thank you!

    Mike
    Attached Files Attached Files
    Last edited by itsawayoflife; 09-04-2018 at 03:50 AM.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Automatically hide/unhide rows based on cell value

    Paste the below code into the Staff worksheet module then hide rows 23:80 on each sheet and give it a go.
    Please Login or Register  to view this content.
    BSB
    Attached Files Attached Files

  3. #3
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Automatically hide/unhide rows based on cell value

    I went a slightly different way but still using the Worksheet_Change() event in the Staff sheet. This also copies the staff names to the other sheets. See attached.

    WBD
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    07-28-2014
    Location
    Perth, Australia
    MS-Off Ver
    2019
    Posts
    31

    Re: Automatically hide/unhide rows based on cell value

    Wow. Thank you so much! My little heart is happy now. :-)

    Cheers,

    Mike

  5. #5
    Registered User
    Join Date
    07-28-2014
    Location
    Perth, Australia
    MS-Off Ver
    2019
    Posts
    31

    Re: Automatically hide/unhide rows based on cell value

    Hello again,

    As I have been playing with the file I noticed two things which I'm wondering if they could be adjusted.

    1) the hide/unhide does not allow row 80 to unhide... it stops at 79.
    2) when I try to protect each sheet (so people cannot mess with the formulas) there is an error and it cannot hide or unhide the protected rows.

    Is there anything which can be done to solve these?

    Please see the new reference file attached.

    Thank you!
    Attached Files Attached Files

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Automatically hide/unhide rows based on cell value

    Which of the solutions provided are you using?
    Each will need amending in a different way.

    BSB

  7. #7
    Registered User
    Join Date
    07-28-2014
    Location
    Perth, Australia
    MS-Off Ver
    2019
    Posts
    31

    Re: Automatically hide/unhide rows based on cell value

    I am using the solution from WideBoyDixon. I think that was what you were asking...

  8. #8
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Automatically hide/unhide rows based on cell value

    I tweaked the solution a little and I've attached an updated workbook. If you protect the sheets, the code will fail because you can't hide/unhide the rows on a protected sheet.

    WBD
    Attached Files Attached Files
    Office 365 on Windows 11, looking for rep!

  9. #9
    Registered User
    Join Date
    07-28-2014
    Location
    Perth, Australia
    MS-Off Ver
    2019
    Posts
    31

    Re: Automatically hide/unhide rows based on cell value

    So perfect! Thanks so much for that. It was really helpful the little 'explanations you added into the coding. I found I learned a lot through that.

    Thanks for your help!

  10. #10
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Automatically hide/unhide rows based on cell value

    For the sake of completeness, it's worth mentioning that you can have the sheets protected and still hide/unhide rows via code.

    If you put the below in the ThisWorkbook module it will fire when the workbook is opened and protect each worksheet.
    The 'UserInterfaceOnly:=True' part allows protected sheets to be manipulated by code but not by the user.
    Please Login or Register  to view this content.
    It can be adapted easily to only protect certain sheets if required.
    This for example will protect all sheets other than the one named 'Staff'.
    Please Login or Register  to view this content.
    BSB
    Last edited by BadlySpelledBuoy; 09-11-2018 at 05:19 AM.

  11. #11
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Automatically hide/unhide rows based on cell value

    Quote Originally Posted by BadlySpelledBuoy View Post
    For the sake of completeness, it's worth mentioning that you can have the sheets protected and still hide/unhide rows via code.

    If you put the below in the ThisWorkbook module it will fire when the workbook is opened and protect each worksheet.
    The 'UserInterfaceOnly:=True' part allows protected sheets to be manipulated by code but not by the user.
    Well I never knew that. Thanks for the information

    WBD

  12. #12
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Automatically hide/unhide rows based on cell value

    Learn something new every day round here mate

    BSB

+ 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] Automatically hide and unhide rows based on selected month
    By dondonordas in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2018, 02:07 AM
  2. Automatically hide/unhide rows based on column A value
    By c.bernardo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-14-2017, 12:30 AM
  3. How to automatically hide/unhide exact number of rows based on a cell's value
    By masud_jahan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-27-2016, 05:23 AM
  4. Automatically hide and unhide rows based on value in cell
    By kmham in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 11-28-2014, 12:03 PM
  5. [SOLVED] Macro to Automatically Hide/Unhide Rows Based on Checkbox
    By bga10s in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2014, 07:32 PM
  6. [SOLVED] Macro to automatically hide or unhide rows based on either a value or no value in a cell
    By WFP111 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2013, 12:28 PM
  7. How Do I Hide/Unhide Rows in Excel based on a cell Value Automatically?
    By mgarcia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2012, 05:20 AM

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