+ Reply to Thread
Results 1 to 2 of 2

word wrap in rows with merged cells

Hybrid View

  1. #1
    Registered User
    Join Date
    05-11-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    word wrap in rows with merged cells

    Hi, In my spreadsheet I must have 7 columns in the first 20 rows. For the remaining rows below that I need only 4 columns.

    So for rows 21 onwards, Columns 2 and 3 have to be merged to give me sufficient width for the text input. I can not have this text word wrap.

    Columns 4 to 7 have to be merged to give me one cell for "lengthy comments". The comments can extend to as much as two or three lines so word wrap is essential here.

    I copied this code below from a contributor whose name I can not remember so apologies for not acknowledging the source by name. It works fine except that: I enter short text in say row 25, merged column 2&3. I then enter longer text in row 25, merged column 4to7 and it wraps correctly.
    Now I go back to merged column 2&3 and replace the contents, again with short text. The entire row height is now reduced to that of single line height which causes the text in row 25, merged column 4to7 to lose its wrap text feature.

    Can the code be modified so that the row height always stays high enough to show the longest word wrapped text entry of the row?
    Many thanks for any help.
    Roger

    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

  2. #2
    Registered User
    Join Date
    05-11-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: word wrap in rows with merged cells

    I will ask the question in a different way as I think I could not have explained myself clearly enough in my original post.
    Between rows 21 and 120, I have merged columns G to L.
    What code do I need, or how can I modify the code in my original post, so that when I type lengthy text into the merged cell of say row 21, it wraps and automatically adjusts that row height to be sufficient for all the contents typed in to be displayed.
    The row must not revert to single line height if I subsequently type a short, single line of text that easily fits into say cell A21.
    Many thanks for any help you can give
    Roger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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