+ Reply to Thread
Results 1 to 5 of 5

Text wrapping on merged cell

  1. #1
    Colin Telfer
    Guest

    Text wrapping on merged cell

    Does anyone know how to get the text to wrap on a range of merged cells
    which adjusts with the row height, i have managed it with a single cell,
    but when merged cells are used it doesn't work. is there a workaround?

    Thanks in advance

    Colin



  2. #2
    Greg Wilson
    Guest

    RE: Text wrapping on merged cell

    I have an adaption from Jim Rech's original code that automates this using
    the ws_change event:

    http://tinyurl.com/n59er

    Alternatively, you can set the column width of a single cell in the same row
    as each merged range the same as the combined column widths of the merged
    range. Insert a formula that references the first cell of the merged range
    (e.g. "=A1"). Therefore, the text in this cell will be exactly the same as
    the merged range. Set wraptext to True. Format it exactly the same except
    have its font colour the same as the cell's interior colour in order to hide
    the text. The cell probably should also be offscreen.

    Then use the ws_change event to force autofit of the cell. The merged range
    will also autofit since it is in the same row.

    Regards,
    Greg

    "Colin Telfer" wrote:

    > Does anyone know how to get the text to wrap on a range of merged cells
    > which adjusts with the row height, i have managed it with a single cell,
    > but when merged cells are used it doesn't work. is there a workaround?
    >
    > Thanks in advance
    >
    > Colin
    >
    >
    >


  3. #3
    Colin Telfer
    Guest

    Re: Text wrapping on merged cell

    Greg

    Thanks for replying, I am a novice to VBA, and not quite sure what to do
    with the code you refer to, I have a spreadsheet with a range of cells
    merged, A4 :D4, which as I would enter the title form a form with a text box
    the value of the text box is entered into the cell which I have managed to
    do, but I want the formatting in the range of merged cells to adjust the row
    hieght accordingly to make it fit and text wrap as well.

    ring3 = TextBox3.Value

    ActiveSheet.Range("A4").Select

    ActiveCell.Value = ring3

    'Worksheets("Sheet1").Range("A4").WrapText = True

    Above is the code used, as you can see I have made the normal cell
    formatting a comment as it does not work for merged cells.

    Much appreciate any help / guidance you can give

    Regards

    Colin

    "Greg Wilson" <[email protected]> wrote in message
    news:[email protected]...
    >I have an adaption from Jim Rech's original code that automates this using
    > the ws_change event:
    >
    > http://tinyurl.com/n59er
    >
    > Alternatively, you can set the column width of a single cell in the same
    > row
    > as each merged range the same as the combined column widths of the merged
    > range. Insert a formula that references the first cell of the merged range
    > (e.g. "=A1"). Therefore, the text in this cell will be exactly the same as
    > the merged range. Set wraptext to True. Format it exactly the same except
    > have its font colour the same as the cell's interior colour in order to
    > hide
    > the text. The cell probably should also be offscreen.
    >
    > Then use the ws_change event to force autofit of the cell. The merged
    > range
    > will also autofit since it is in the same row.
    >
    > Regards,
    > Greg
    >
    > "Colin Telfer" wrote:
    >
    >> Does anyone know how to get the text to wrap on a range of merged cells
    >> which adjusts with the row height, i have managed it with a single cell,
    >> but when merged cells are used it doesn't work. is there a workaround?
    >>
    >> Thanks in advance
    >>
    >> Colin
    >>
    >>
    >>




  4. #4
    Greg Wilson
    Guest

    Re: Text wrapping on merged cell

    Paste the code to the worksheet's class module - i.e. Sheet1(Sheet1) in the
    list of Microsoft Excel Objects available through the VBE's Project Explorer
    window. The code will then fire automatically in response to change made to
    cell contents (worksheet_change event).

    You don't need to tell it to wrap the text. The Wraptext property of the
    merged range needs to be set though: Format > Cells > Alignment tab > "Wrap
    text" checkbox. This need only be done once and is probably already set.

    I am assuming that the code you appended is in a Userform code module. It is
    possible that earlier versions of Excel (pre xl2000) won't fire the ws_change
    event in response to programmatic change made to cell contents in case you
    are running xl97 or earlier.

    I simplified your code. Note that it is seldom necessary to programmatically
    select anything. Just refer to it directly in your code.

    Dim ring3 As String
    ring3 = TextBox1.Value
    ActiveSheet.Range("A4").Value = ring3

    Regards,
    Greg


    "Colin Telfer" wrote:

    > Greg
    >
    > Thanks for replying, I am a novice to VBA, and not quite sure what to do
    > with the code you refer to, I have a spreadsheet with a range of cells
    > merged, A4 :D4, which as I would enter the title form a form with a text box
    > the value of the text box is entered into the cell which I have managed to
    > do, but I want the formatting in the range of merged cells to adjust the row
    > hieght accordingly to make it fit and text wrap as well.
    >
    > ring3 = TextBox3.Value
    >
    > ActiveSheet.Range("A4").Select
    >
    > ActiveCell.Value = ring3
    >
    > 'Worksheets("Sheet1").Range("A4").WrapText = True
    >
    > Above is the code used, as you can see I have made the normal cell
    > formatting a comment as it does not work for merged cells.
    >
    > Much appreciate any help / guidance you can give
    >
    > Regards
    >
    > Colin
    >
    > "Greg Wilson" <[email protected]> wrote in message
    > news:[email protected]...
    > >I have an adaption from Jim Rech's original code that automates this using
    > > the ws_change event:
    > >
    > > http://tinyurl.com/n59er
    > >
    > > Alternatively, you can set the column width of a single cell in the same
    > > row
    > > as each merged range the same as the combined column widths of the merged
    > > range. Insert a formula that references the first cell of the merged range
    > > (e.g. "=A1"). Therefore, the text in this cell will be exactly the same as
    > > the merged range. Set wraptext to True. Format it exactly the same except
    > > have its font colour the same as the cell's interior colour in order to
    > > hide
    > > the text. The cell probably should also be offscreen.
    > >
    > > Then use the ws_change event to force autofit of the cell. The merged
    > > range
    > > will also autofit since it is in the same row.
    > >
    > > Regards,
    > > Greg
    > >
    > > "Colin Telfer" wrote:
    > >
    > >> Does anyone know how to get the text to wrap on a range of merged cells
    > >> which adjusts with the row height, i have managed it with a single cell,
    > >> but when merged cells are used it doesn't work. is there a workaround?
    > >>
    > >> Thanks in advance
    > >>
    > >> Colin
    > >>
    > >>
    > >>

    >
    >
    >


  5. #5
    Colin Telfer
    Guest

    Re: Text wrapping on merged cell

    Thnaks Greg its worked a treat

    Regards

    Colin

    "Greg Wilson" <[email protected]> wrote in message
    news:[email protected]...
    > Paste the code to the worksheet's class module - i.e. Sheet1(Sheet1) in
    > the
    > list of Microsoft Excel Objects available through the VBE's Project
    > Explorer
    > window. The code will then fire automatically in response to change made
    > to
    > cell contents (worksheet_change event).
    >
    > You don't need to tell it to wrap the text. The Wraptext property of the
    > merged range needs to be set though: Format > Cells > Alignment tab >
    > "Wrap
    > text" checkbox. This need only be done once and is probably already set.
    >
    > I am assuming that the code you appended is in a Userform code module. It
    > is
    > possible that earlier versions of Excel (pre xl2000) won't fire the
    > ws_change
    > event in response to programmatic change made to cell contents in case you
    > are running xl97 or earlier.
    >
    > I simplified your code. Note that it is seldom necessary to
    > programmatically
    > select anything. Just refer to it directly in your code.
    >
    > Dim ring3 As String
    > ring3 = TextBox1.Value
    > ActiveSheet.Range("A4").Value = ring3
    >
    > Regards,
    > Greg
    >
    >
    > "Colin Telfer" wrote:
    >
    >> Greg
    >>
    >> Thanks for replying, I am a novice to VBA, and not quite sure what to do
    >> with the code you refer to, I have a spreadsheet with a range of cells
    >> merged, A4 :D4, which as I would enter the title form a form with a text
    >> box
    >> the value of the text box is entered into the cell which I have managed
    >> to
    >> do, but I want the formatting in the range of merged cells to adjust the
    >> row
    >> hieght accordingly to make it fit and text wrap as well.
    >>
    >> ring3 = TextBox3.Value
    >>
    >> ActiveSheet.Range("A4").Select
    >>
    >> ActiveCell.Value = ring3
    >>
    >> 'Worksheets("Sheet1").Range("A4").WrapText = True
    >>
    >> Above is the code used, as you can see I have made the normal cell
    >> formatting a comment as it does not work for merged cells.
    >>
    >> Much appreciate any help / guidance you can give
    >>
    >> Regards
    >>
    >> Colin
    >>
    >> "Greg Wilson" <[email protected]> wrote in message
    >> news:[email protected]...
    >> >I have an adaption from Jim Rech's original code that automates this
    >> >using
    >> > the ws_change event:
    >> >
    >> > http://tinyurl.com/n59er
    >> >
    >> > Alternatively, you can set the column width of a single cell in the
    >> > same
    >> > row
    >> > as each merged range the same as the combined column widths of the
    >> > merged
    >> > range. Insert a formula that references the first cell of the merged
    >> > range
    >> > (e.g. "=A1"). Therefore, the text in this cell will be exactly the same
    >> > as
    >> > the merged range. Set wraptext to True. Format it exactly the same
    >> > except
    >> > have its font colour the same as the cell's interior colour in order to
    >> > hide
    >> > the text. The cell probably should also be offscreen.
    >> >
    >> > Then use the ws_change event to force autofit of the cell. The merged
    >> > range
    >> > will also autofit since it is in the same row.
    >> >
    >> > Regards,
    >> > Greg
    >> >
    >> > "Colin Telfer" wrote:
    >> >
    >> >> Does anyone know how to get the text to wrap on a range of merged
    >> >> cells
    >> >> which adjusts with the row height, i have managed it with a single
    >> >> cell,
    >> >> but when merged cells are used it doesn't work. is there a
    >> >> workaround?
    >> >>
    >> >> Thanks in advance
    >> >>
    >> >> Colin
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>




+ 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