+ Reply to Thread
Results 1 to 4 of 4

Macro to expand and collapse rows based on criteria in cells

  1. #1
    Registered User
    Join Date
    08-22-2014
    Location
    San Diego, Ca
    MS-Off Ver
    2010
    Posts
    33

    Macro to expand and collapse rows based on criteria in cells

    Hello again,

    I am looking for a macro to expand and collapse a range based on certain criteria. For example. if my cell has the text "Yes", all rows that are beneath it in the expandable section would collapse. I currently have a macro that expands and collapses all the sections based on text in a cell, but I am looking to expand and collapse sections, not the whole document. Any suggestions. I am using Sheet4.

    I have attached a sample file.
    Attached Files Attached Files
    Last edited by jholiday78; 09-22-2015 at 04:42 PM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to expand and collapse rows based on criteria in cells

    Hi jholiday78,

    See the attached file which contains an updated copy of your workbook. The following code is used to do what you requested:

    In an ordinary code module such as Module1:
    Please Login or Register  to view this content.
    Lewis

  3. #3
    Registered User
    Join Date
    08-22-2014
    Location
    San Diego, Ca
    MS-Off Ver
    2010
    Posts
    33

    Re: Macro to expand and collapse rows based on criteria in cells

    Hi Lewis,

    It took me a bit to figure it out, but I understand what you did now. This is great.

    I know I added buttons in there, but I was wondering is there a way to eliminate the button and have the action triggered by the text "Yes", or "No"? I understand it, but I can see my co-workers getting frustrated that they have to select from the drop down first and then click on a button to expand/collapse. Does that make sense?

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to expand and collapse rows based on criteria in cells

    is there a way to eliminate the button and have the action triggered by the text "Yes", or "No"?
    My initial thought several days ago was that this is what you really needed, but didn't ask for. See the attached file which does NOT CHANGE the original code, but adds the code below (which is included in the new file).

    The following code in the ThisWorkbook module makes sure the rows are expanded/collapsed per 'Yes/No' (case insensitive) in Column 'B' when the Workbook is OPENED.
    Please Login or Register  to view this content.
    The following code in the 'Sheet2' module expands/collapses rows per 'Yes/No' in Column 'B' each time there is a change in Column 'B'.
    NOTE: The items in red below previously existed in the 'Sheet2' module and should ONLY exist ONCE in the module.
    Please Login or Register  to view this content.
    Lewis

+ 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. Macro to expand a row and then collapse
    By ictodd in forum Excel General
    Replies: 1
    Last Post: 01-18-2015, 04:54 PM
  2. Macro te expand/collapse range
    By graiggoriz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-12-2014, 06:36 AM
  3. Expand / Collapse Groups via Macro
    By bmasella in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2014, 10:57 PM
  4. How to expand and collapse (unhide and hide) rows in a tree like structure
    By Scott N in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-21-2013, 05:57 PM
  5. Excel Macro to Collapse/Expand grouped rows and columns
    By magjayeck in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2013, 10:58 AM
  6. Expand/Collapse Rows
    By [email protected] in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-18-2006, 04:30 AM
  7. Expand and Collapse Cells?
    By fernandes70 in forum Excel General
    Replies: 1
    Last Post: 03-19-2005, 01:50 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