View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach[_6_] Otto Moehrbach[_6_] is offline
external usenet poster
 
Posts: 201
Default divide multiline text cell across several rows

There is no built-in way to do that in Excel. You would have to 'roll your
own' in this case. I often need to do what you describe so I wrote a macro
to do it for me. This macro takes whatever is in the active cell, assuming
the entry is longer than the cell is wide, and inserts the necessary blank
rows below that cell and cuts and pastes the cell entry to occupy as many
rows, as wide as the cell, as it takes.
This macro is not refined and it doesn't do the job perfectly every
time. Also, it will handle upper case differently than lower case, and you
will need to adjust the constants to work with your font. But for me it
does the job. HTH Otto
Sub LongCellFix()
Dim Co As Integer
Dim FirstPart As String, TheRest As String
Dim Space As Integer, Cou As Integer, i As Range
Dim CutOff As Integer
CutOff = Int(ActiveCell.ColumnWidth * 1.28)
ActiveCell.Value = Trim(ActiveCell.Value)
Set i = ActiveCell
For Cou = 1 To 300
If Len(i) < CutOff + 1 Then Exit For
For Co = 0 To 50
If Mid(i, CutOff - Co, 1) = " " Then Exit For
Next
Space = CutOff - Co
FirstPart = Trim(Left(i, Space))
TheRest = Trim(Right(i, Len(i) - Space))
If Not i.Offset(1).Value = "" Then
i.Offset(1, 0).Rows("1:1").EntireRow. _
Insert Shift:=xlDown
i.Value = FirstPart
i.Offset(1).Value = TheRest
Set i = i.Offset(1)
ActiveCell.Select
Next
End Sub
"Stuart" wrote in message
...
Say I paste text data (essentially a sentance(s) ) into B2,
where Col B has a columnwidth of 55 and the RowHeight
is set to 12.75.
I then enable Wraptext in this cell, and the RowHeight now
increases to 51 (so the data is occupying 3 + lines in the
cell).
I save the workbook, close it, then reopen it.

Is there a way to reformat the data in B2, so that it will
then occupy 4no 12.75 high rows in colB?

I believe the data will only be space delimited.

Regards.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.661 / Virus Database: 424 - Release Date: 19/04/2004