+ Reply to Thread
Results 1 to 8 of 8

Worksheet Change Hide/Unhide rows automatically

  1. #1
    Registered User
    Join Date
    09-12-2016
    Location
    England, UK
    MS-Off Ver
    MS 365
    Posts
    59

    Worksheet Change Hide/Unhide rows automatically

    Hello all,

    I am attempting to write some code that will hide/unhide rows in a certain range based on the values in a cell. I have come up with the basic code below, however I cant get it to trigger at all when I am in the worksheet. I want it to trigger whenever a one of the cells change to 1 or 2. Can someone please help me?

    Please Login or Register  to view this content.

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

    Re: Worksheet Change Hide/Unhide rows automatically

    I'm guessing you've just coded that in a standard module. It is not a true Worksheet Change event handler. That sits behind the Worksheet you want to monitor in the "Worksheet class module". It has a Target parameter which refers to the cell, or range of cells, that have changed. It is usual to restrict monitoring of cells to a specific range; in this case, probably column Q.

    Suggest you post a sample workbook.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    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
    Registered User
    Join Date
    09-12-2016
    Location
    England, UK
    MS-Off Ver
    MS 365
    Posts
    59

    Re: Worksheet Change Hide/Unhide rows automatically

    Hi Trevor, thank you for replying. I have attached a copy of an example one here. I have added it to the worksheet's code itself (right click on worksheet > edit code). Can you let me know where I have gone wrong please? Thank you for your help.
    Attached Files Attached Files

  4. #4
    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,530

    Re: Worksheet Change Hide/Unhide rows automatically

    You'd want something like this:

    Please Login or Register  to view this content.
    There are two problems, one trivial, one not so. The trivial problem is that End(xlUp) ignores hidden rows so it could be a lot less that the rows of data. This can be remedied by looking at the UsedRange.Rows.Count. That can be wrong but it will always be greater than or equal to the current number of rows of data.

    The less trivial problem is that once you have set a value to 1 and the row is hidden, you can't see the row to unhide it, so you'll have to manually unhide all the rows to see and change the values in column Q.

    Personally, I'd be inclined to use Autofilter to hide and unhide the rows.

  5. #5
    Registered User
    Join Date
    09-12-2016
    Location
    England, UK
    MS-Off Ver
    MS 365
    Posts
    59

    Re: Worksheet Change Hide/Unhide rows automatically

    That worked perfectly! I cant thank you enough Trevor. I will be looking into using autofilter too, I didnt think about that. Thank you for the explanation, I really appreciate 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,530

    Re: Worksheet Change Hide/Unhide rows automatically

    You're welcome. Thanks for the rep.

  7. #7
    Registered User
    Join Date
    08-11-2011
    Location
    Louisiana
    MS-Off Ver
    Excel 2016 & 365
    Posts
    39

    Re: Worksheet Change Hide/Unhide rows automatically

    I have a similar issue but I want to hide a row that has certain values in one column. I want the rows to be hidden in which that column is not the same as a dropdown. The list is changing regularly so the number of rows with data isn't consistent.

    For instance,
    Let's say I have a list of people in multiple locations. The column with the location is I. At the moment, I have data from A2:K38 as Row 1 is headers. I have a dropdown in N1 which is based on locations in O1:Q1. What I want is for rows with a different location from the value in N1 to be hidden.

    If I choose Chicago in the dropdown, all other cities will be hidden.

    I've searched online and not found anything to work. I had found something somewhere yesterday but it did nothing and I didn't save it. I do know it was a macro saved on the worksheet. Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Not sure if this script would apply to my situation.

    Thanks in advance.

  8. #8
    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,530

    Re: Worksheet Change Hide/Unhide rows automatically

    @cajunlibra: you would use a Worksheet_Change event handler monitoring the drop down cell. Then Filter the list using Autofilter.

    Note though ... Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

+ 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. 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
  2. [SOLVED] Hide/Unhide Rows Automatically in a specified range (H4:AG111)
    By Staind2b in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2014, 06:04 PM
  3. [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
  4. Automatically Hide/Unhide rows in Excel
    By sanjeeva.vakada in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-06-2014, 10:16 PM
  5. Automatically hide/unhide rows
    By andyb63uk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2012, 05:41 PM
  6. 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
  7. Can't hide/unhide rows under worksheet change event?
    By Don Wiss in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2005, 07:02 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