Consulting

Results 1 to 5 of 5

Thread: Autofit Merged Cells / Autosize Formatting

  1. #1

    Autofit Merged Cells / Autosize Formatting

    I know it sounds simple, but I'm having no luck with it...

    How do you autofit, specifically row height, on a merged cell?

    Thank you!

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    a quick search in google makes me think it's a problem of mankind

    http://groups.google.com/group/micro...c6bca447bd8902
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    If the merged cells are on the same row, you might try 'Centre across selection' for the horizontal alignment instead of merging the cells, and 'wrap text' checked. Then double click the lower border of the row's label?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    Thank you so much for your time. I will try these out tomorrow!

  5. #5
    The google link gave me an error message, but I did fild this code from Greg Wilson, which works great except if you have two merged cells in the same row (I have no control over the format, so I can't delete the dread merged cells). If you have a11 & b11 merged and c11 & d11, it's going to size the row height according to the last change event, not the larger of the merged cells. Does anyone have any ideas around this? Thanks again!!!

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim NewRwHt As Single
    Dim cWdth As Single, MrgeWdth As Single
    Dim c As Range, cc As Range
    Dim ma As Range

    With Target
    If .MergeCells And .WrapText Then
    Set c = Target.Cells(1, 1)
    cWdth = c.ColumnWidth
    Set ma = c.MergeArea
    For Each cc In ma.Cells
    MrgeWdth = MrgeWdth + cc.ColumnWidth
    Next
    Application.ScreenUpdating = False
    ma.MergeCells = False
    c.ColumnWidth = MrgeWdth
    c.EntireRow.AutoFit
    NewRwHt = c.RowHeight
    c.ColumnWidth = cWdth
    ma.MergeCells = True
    ma.RowHeight = NewRwHt
    cWdth = 0: MrgeWdth = 0
    Application.ScreenUpdating = True
    End If
    End With
    End Sub

Posting Permissions

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