Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Western NY, USA
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am automatically inserting text into some cells. I want to have the cell height adjust automatically to fit the text. I do not know how to determine a proper fit via code. I do know that
    range("somerange").entirerow.autofit
    does not work.

    One thing I thought about is to create a new workbook with the cells the proper width, do an auto fit, determine the height then throw away the temporary workbook.

    Case 1.
    Text is in colum "O", columns A & B are titles, Columns C-P are hidden, but may contain text. I want to size the row so that the text in column "O" fits nicely.

    Case 2:
    Text is centered across mutliple columns.

    Thanks.
    Attached Files Attached Files

  2. #2
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    try

    Range("Some Range").WrapText = True
    Regards
    Don

  3. #3
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    1)While it appears you can adjust the COLUMN width based on a the text in a particular ROW, the height of a ROW is dependent on all the entries in the row. Thus you will need to unwrap all the text in the row and only wrap the column of interest, then autofit:

    Rows("7:7").WrapText = False
    Range("O7").WrapText = True
    Rows("7:7").EntireRow.AutoFit

    2) The problem is that your text is not really centered across the selection but is Merged and centered. Autoheight is not available when the cells are merged. If you remove the merging and then center across the selection autofit will work:

    With Range("A1414")
    .MergeCells = False
    .HorizontalAlignment = xlCenterAcrossSelection
    .EntireRow.AutoFit
    End With


    Steve

  4. #4
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Western NY, USA
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. That works, as does autofit, if I don't have any merged cells. Once the merged cells are in the mix the behavour changes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •