+ Reply to Thread
Results 1 to 5 of 5

Auto Adjusting Row Height via Macro

  1. #1
    Registered User
    Join Date
    01-30-2014
    Location
    Brazil
    MS-Off Ver
    Excel 2016
    Posts
    46

    Auto Adjusting Row Height via Macro

    Hello guys. I would like some help, if possible.
    I'm automating the row adjusting of some excel reports, depending on the lines of text in each cell in the A column. This is how I did it:

    1 - I calculate the number of lines (wraped text) in each cell via formula:
    =LEN(A1)-LEN(SUBSTITUTE(A1;CHAR(10);""))+1
    I put this formula at B1. This will return me the number of lines in the text of A1.
    Then I repeat this through the whole part that involves texts (there's some images below that I do not want to adjust).

    2 - I create a macro and assign it to a button, with the following code:
    Please Login or Register  to view this content.
    With that I made each cell have a row height of "number of lines" times 16.5.


    That worked but the number of cells varies from report to report. How can I improve this? I would like to check the number of lines via code instead of that formula, then I would have more control and could repeat this process until the last cell with text. Any ideas?
    I'm new to excel and VBA, sorry! Thank you!

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Auto Adjusting Row Height via Macro

    Try this:

    Please Login or Register  to view this content.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Registered User
    Join Date
    01-30-2014
    Location
    Brazil
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Auto Adjusting Row Height via Macro

    Thank you Pauleyb. I guess that solves the problem of having variable number of lines. But do you know how can I count the lines without that formula that I used?
    Can I implement this directly on VBA code?

    =LEN(A1)-LEN(SUBSTITUTE(A1;CHAR(10);""))+1

  4. #4
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Auto Adjusting Row Height via Macro

    Yes, but in VBA SUBSTITUTE is REPLACE, and CHAR is CHR.

  5. #5
    Registered User
    Join Date
    01-30-2014
    Location
    Brazil
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Auto Adjusting Row Height via Macro

    Thank you, going to try.

+ 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. Adjusting row height to fit text
    By Ivan Sauri in forum Excel General
    Replies: 4
    Last Post: 12-12-2012, 10:26 AM
  2. Macro for auto adjusting axis on charts
    By ExcelNUBs in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-10-2012, 05:24 AM
  3. self adjusting row height
    By Sebastian1942 in forum Excel General
    Replies: 2
    Last Post: 01-06-2010, 08:43 AM
  4. Adjusting row height after filtering
    By kiteman in forum Excel General
    Replies: 0
    Last Post: 11-09-2009, 10:13 AM
  5. Row Height auto-adjusting?
    By pgleek in forum Excel General
    Replies: 1
    Last Post: 08-23-2007, 04:42 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