+ Reply to Thread
Results 1 to 13 of 13

Formula or code to hide or unhide rows based on value in a cell

  1. #1
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Formula or code to hide or unhide rows based on value in a cell

    I need to hide rows in my worksheet. Is there a way to do the following:

    If the value in a cell is "Hide" can I hide the remaining rows in the worksheet until row 408 is hidden. Example - If the first "Hide" i encounter in column "U" row 175 then I want to hide rows 175 thru 408 regardless of the values in $U176:$U408.

    I've attached a sample workbook - the worksheet is named CA_RR1_D

    Thanks for any help you can offer
    Attached Files Attached Files

  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,434

    Re: Formula or code to hide or unhide rows based on value in a cell

    Maybe something like this to start you off:

    Please Login or Register  to view this content.

    Regards, TMS
    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 Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Formula or code to hide or unhide rows based on value in a cell

    Hi there,

    Here's a "manual" way of doing it

    Please Login or Register  to view this content.
    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  4. #4
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: Formula or code to hide or unhide rows based on value in a cell

    Hi TMS,

    Thank you for that code, I am a 100% novice with VBA code - Could you let me know what column the code is set to check - I don't know enough about the VBA to see that. Once I put the code in will it execute whenever a cell in column U changes?

  5. #5
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: Formula or code to hide or unhide rows based on value in a cell

    Hi Greg,

    I have put your code in but nothing happens - do I need to do anything to activate the code? I'm have virtually no experience with VBA.

    Thanks for your help

  6. #6
    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,434

    Re: Formula or code to hide or unhide rows based on value in a cell

    Well, strictly, it will monitor anything in column A and anything that updates the formula in column A. Because column A has formulas in it, changes to the value of the formula won't fire the Change event. However, it makes it easier for testing: I can either type something directly in column A and see what happens, or I can change the formula to something simpler so I don't have to work out what values I need to get the word "hide" in column A.

    Slight change:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Formula or code to hide or unhide rows based on value in a cell

    Hi again,

    Open the attached workbook and click on the button located in Cell U1 - that should do it

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: Formula or code to hide or unhide rows based on value in a cell

    Greg,

    Thanks for that coding - It works great!!! I will mark this thread resolved

  9. #9
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: Formula or code to hide or unhide rows based on value in a cell

    ok, thanks - I appreciate your time. The coding from Greg M and you both worked like I wanted!!! Thanks so much. I am marking this thread resolved.

  10. #10
    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,434

    Re: Formula or code to hide or unhide rows based on value in a cell

    You're welcome. Thanks for the rep.

  11. #11
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Formula or code to hide or unhide rows based on value in a cell

    Hi again,

    Many thanks for your feedback and also for the Reputation increase

    Very pleased that I was able to help.

    Best regards,

    Greg M

  12. #12
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: Formula or code to hide or unhide rows based on value in a cell

    Hi Greg,

    I used your code and it did exactly what I asked but after further review of the results I would like to make a change. Can I examine in reverse and check last row to first and then exit when I find "UNHIDE" in column U. The reason is the way I set it up originally I wind up with several header rows at the end which I don't want to print. I've changed my formula to mark all header rows (First row after each page break) with value of "HIDE". I tried reversing the "For " statement to be LAST_ROW To FIRST_ROW but that doesn't do anything. I reverted this thread to unresolved - but let me know if I need to mark it back to resolved and start a new thread.

    Thanks again for your help.

  13. #13
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Jacksonville, Florida
    MS-Off Ver
    Excel 2016
    Posts
    313

    Re: Formula or code to hide or unhide rows based on value in a cell

    OOPS - I found out on Google how to do what I need by adding "step -1" to the for loop. I'll re-mark as solved. Hope I didn't waste your time

    Thanks much!!

+ 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 based on a cell value
    By Silver13 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-23-2015, 03:00 PM
  2. Vb code to hide/unhide rows based on entries on another sheet
    By tcrjmom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2015, 01:15 PM
  3. Hide/Unhide Rows based on cell value containing formula
    By MikeIke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2014, 04:01 AM
  4. Need code to hide and unhide a row based on if other rows are hidden or unhidden
    By aradov in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-20-2014, 02:06 PM
  5. [SOLVED] How VB code can unhide/hide rows based on combobox selection?
    By jgomez in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-04-2012, 01:25 PM
  6. Replies: 1
    Last Post: 08-21-2012, 02:46 PM
  7. Hide/Unhide rows based on cell value (result of formula)
    By tjanda in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-17-2012, 05:57 PM

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