+ Reply to Thread
Results 1 to 9 of 9

Expand row when cell selected; shrink when deselected

  1. #1
    Registered User
    Join Date
    04-11-2017
    Location
    Philly
    MS-Off Ver
    Professional Plus 2013
    Posts
    4

    Expand row when cell selected; shrink when deselected

    Disclaimer: I'm brand new to VBA and I don't know the language... or how to do almost anything. My apologies.


    I'm creating an FAQ for staff who answer the phone, and some of the answers (in column C) are quite long. To make the spreadsheet easy to navigate quickly, I would like all rows to have a height of 30 when they are not selected. However, when any cell in a row is selected, that row should expand to fit all content in the cell in column C. (All of the cells have wrapped text.) Once an expanded row is no longer selected, it should snap back to height 30.

    In other words...
    • Deselected rows: height = 30
    • Any row with a selected cell: height = autofit
    • Row no longer selected: height = 30

    Please note that I do not want to use text boxes, because I've also got a search filter running and the content in column C needs to be searchable.


    Thanks in advance for sharing your wisdom.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Expand row when cell selected; shrink when deselected

    .
    .
    Paste this into the Sheet Level module :

    Please Login or Register  to view this content.
    Format column CENTER vertically and one of the three selections for HORIZONTAL.

    When the user double clicks on the cell, the wrapped text displays.
    When they click outside the cell, the wrapped text rolls up.

    Format all cells for the desired size from the worksheet.
    Attached Files Attached Files
    Last edited by Logit; 04-11-2017 at 04:37 PM.

  3. #3
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Expand row when cell selected; shrink when deselected

    I think you need something like this.
    Shrinking and expanding is done in the Worksheet_SelectioChange() procedure.
    "MyRange" should be replaced by the range you're using. Preferably that would be a table.
    Attached Files Attached Files
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  4. #4
    Registered User
    Join Date
    04-11-2017
    Location
    Philly
    MS-Off Ver
    Professional Plus 2013
    Posts
    4

    Re: Expand row when cell selected; shrink when deselected

    Thanks for the prompt reply, Logit! But, uh, nothing is happening.

    So I opened up Book1 - Sheet1 (Code) in VBA. I pasted your code and edited the range:

    Please Login or Register  to view this content.
    I went back to Sheet 1 and set the height for all rows to 30. And then I tried clicking around, but no matter where I click, nothing expands.

    This could be a really stupid question, but am I supposed to save something somewhere to make the macro start running?

  5. #5
    Registered User
    Join Date
    04-11-2017
    Location
    Philly
    MS-Off Ver
    Professional Plus 2013
    Posts
    4

    Re: Expand row when cell selected; shrink when deselected

    Tsjallie, this is beautiful, and it works perfectly. Thank you so much!

  6. #6
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Expand row when cell selected; shrink when deselected

    You're welcome
    It may need some adjustment to leave filtered rows hidden.
    If that's so, please upload your workbook.

  7. #7
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Expand row when cell selected; shrink when deselected

    Just checked and the filter is untouched.

  8. #8
    Registered User
    Join Date
    04-11-2017
    Location
    Philly
    MS-Off Ver
    Professional Plus 2013
    Posts
    4

    Re: Expand row when cell selected; shrink when deselected

    Everything is working perfectly! This is most excellent. Some day when I have time I'll have to study up on the syntax so I'll have a better idea of why it's working.

  9. #9
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Expand row when cell selected; shrink when deselected

    Try running the attachment in post #2.

    Glad you have it all sorted out !

    Cheers.

+ 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] Need to expand a report that pulls selected date's activities, to range of dates
    By taylorsm in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-27-2017, 10:09 AM
  2. Shrink/Expand Print Area
    By HangMan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-28-2015, 11:51 AM
  3. Expand/Collaps Group Based on Selected Cell
    By FallingDown in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2014, 03:58 AM
  4. Expand Selected Range
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-16-2009, 12:10 PM
  5. Replies: 2
    Last Post: 04-16-2009, 08:19 AM
  6. [SOLVED] Shrink and expand a number of columns/rows
    By balles in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-17-2006, 12:35 PM
  7. Replies: 0
    Last Post: 02-16-2005, 04:05 AM

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