+ Reply to Thread
Results 1 to 9 of 9

Autofit row height based on a number in that row

  1. #1
    Forum Contributor
    Join Date
    04-15-2008
    Location
    Texas, USA
    MS-Off Ver
    M365 Excel Version 2210
    Posts
    198

    Autofit row height based on a number in that row

    Is there a way to autofit the row height to whatever a number is in that row without VBA? e.g. if cell b14 has the numeral "40" in it, can I autofit row be to 40 without VBA?. I am using Excel 365.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    re: Autofit row height based on a number in that row

    Fraid not. It will have to be done manually, or with code.

  3. #3
    Forum Contributor
    Join Date
    04-15-2008
    Location
    Texas, USA
    MS-Off Ver
    M365 Excel Version 2210
    Posts
    198

    re: Autofit row height based on a number in that row

    Got it but disappointed. Thanks for that.

    Might you know the code to do that and, if so, does that code need to be on every sheet or the ThisWorkbook Object?

  4. #4
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,059

    re: Autofit row height based on a number in that row

    Any specific reason why you want a certain row height for a certain row?

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Autofit row height based on a number in that row

    Quote Originally Posted by aresquare1 View Post
    does that code need to be on every sheet or the ThisWorkbook Object?
    That depends on exactly what you want to do. Please attach a sample workbook and describe:

    Which cells you want this to apply to?
    What action will trigger the resize of the row height. That is, do you want to push a button? Have it happen automatically when a number is added, or changes?

    Here's a quick example. Type a number into any cell in column A. That row will be set to have a height of that number in points.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  6. #6
    Forum Contributor
    Join Date
    04-15-2008
    Location
    Texas, USA
    MS-Off Ver
    M365 Excel Version 2210
    Posts
    198

    Re: Autofit row height based on a number in that row

    Sorry Jeff. I downloaded your row height.xlsm and entered 13 in A3 and 100 in A4. Nothing happened. I attached, I think, a screen shot of the worksheet after I entered the numbers.
    Attachment 863844

    Also, my problem is that if we got your example to work for me, I don't know how to get the number to be entered that I want. Let's say the row in question has a cell with 3 rows in one cell with wrapped text meaning no line breaks, just Excel wrapping the text onto two additional rows of text in the cell. If an Excel formula or VBA could tell me there were 3 rows, I could get the row height for the font I wanted, say 15.6, and add say, 7 to that meaning it would set the row height to print what looks like 3-1/2 rows of text. That way the last row in my cell would never get cropped off in printing.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Autofit row height based on a number in that row

    Your attachment was not valid. To attach an image, first click Go Advanced under your edit box. Then click in the text to set the cursor to where you want the image to appear, then press the image icon and attach your image.

    It sounds like you are not permitting macros to run. Here is a screen video of me showing the same file: https://youtu.be/OgkwAjyNoic

    I don't know how to get the number to be entered that I want
    It would save trouble to state your requirements up front. I answered your question, but you didn't really ask for what you need.

    Automatically setting row height based on the amount of text in a cell that has wrapped text is tricky because it depends on the attributes of the specific font that you are using. Also most fonts are proportional fonts, so you can't just count the number of characters, and there is no way for Excel to tell you where it is wrapping the lines. The necessary cell height will vary depending on the font, character size, and the specific text that is in the cell.

    I think I answered a question like this some years ago, and there are some things you can do but none of them are great. I'll get back you if I can dig it up.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Autofit row height based on a number in that row

    Here are some examples of the same text in different fonts. The second column gives row height. This doesn't take into account fonts of different sizes, or different text.

    row height.jpg

  9. #9
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,223

    Re: Autofit row height based on a number in that row

    There are two problems with auto sizing cell heights:
    1. After auto sizing an additional blank line may appear in the cell.
    2. after auto sizing, the text in the cell is fully visible, while on the printout the last line of text may be truncated (in whole or in part).

    I once wrote the following macro to remove an unnecessary blank line, but by adding a certain number of points to the height of the shape, the second problem can be solved as well.

    I assume that the height of cell B2 should be corrected.
    Please Login or Register  to view this content.
    Artik
    Last edited by Artik; 03-24-2024 at 07:37 PM.

+ 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. autofit row height
    By 9599lorenzo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2015, 06:41 AM
  2. Replies: 1
    Last Post: 01-14-2015, 11:39 AM
  3. Autofit row height
    By maximoomoo in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-15-2014, 05:50 PM
  4. [SOLVED] VBA to autofit row & height
    By charscribbles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2014, 11:08 PM
  5. [SOLVED] Autofit Row Height
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 06-25-2013, 03:36 PM
  6. Macro to autofit row height, and then reduce back to original height
    By LesleyRicco in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2013, 09:12 PM
  7. [SOLVED] Autofit row height
    By Wellie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2005, 10:06 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