+ Reply to Thread
Results 1 to 3 of 3

Setting Row Height

  1. #1
    Registered User
    Join Date
    02-06-2011
    Location
    Minneapolis
    MS-Off Ver
    Excel 2011
    Posts
    19

    Setting Row Height

    Here's my problem.

    I have an excel sheet with a merged cell (it is three columns merged into one). I would like a script to set the row height to just fit the contents of the merged cells. The cell in question will have a varying amount of text (unpredictable).

    I have found a few rather complicated VBA scripts floating around, but I was thinking of the following "easy" work-around, though I haven't gotten it work just yet.

    Here's the plan: I will link the text from the merged cell to a non-merged cell on a much lower and further right part of the current worksheet (or on a new worksheet if that's helpful). The cell with the copied data will be of the same width as the merged cell on the main part of the worksheet.

    I will use the .autofit method on the copied cell (which should work because it's not a merged cell), will then copy the height of that cell to a variable, then set the height of the merged cell to be the same as the variable.

    e.g.
    A1:C1 are merged into A1
    A1 (merged) is 5 inches wide (with a lot of text it in)
    set E5 width to 5 inches wide
    set E5 to "=A1"

    run script

    script
    rows(5).autofit
    RH = rows(5).RowHeight
    rows(1).RowHeight = RH


    Assuming the plan will work, I need help with the script syntax.

    Thanks in advance!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Setting Row Height

    If that's your approach, just use an unmerged cell in the same row, and you don't need any code at all.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    02-06-2011
    Location
    Minneapolis
    MS-Off Ver
    Excel 2011
    Posts
    19

    Re: Setting Row Height

    I need at least some code, because I need this to happen without purposeful user intervention.

    But. Your idea was a very good one. I hadn't checked if .Autofit would work on cells further to the right but in the same row. It does. Yay!

    So the basic idea is to set up the same width cells as the merged cells just a few dozen cells to the right of the main spreadsheet data. The end users will never scroll over their and .Autofit works.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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