View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Stefi
 
Posts: n/a
Default separate whole words

Hi Norika,

Try this UDF:

Public Function CutToPieces(StrToCut As String, CutAt As Integer, PartNo As
Integer) As String
Dim PieceArray1() As String
Dim PieceArray2() As String
PieceArray1 = Split(StrToCut, , -1)
darab1 = UBound(PieceArray1)
darab2 = 0
strpiece1 = Join(PieceArray1)
strpiece2 = ""
Do While Len(strpiece1) CutAt
ReDim Preserve PieceArray2(darab2)
For d2 = 0 To darab2 - 1
PieceArray2(d2 + 1) = PieceArray2(d2)
Next d2
PieceArray2(0) = PieceArray1(darab1)
darab1 = darab1 - 1
ReDim Preserve PieceArray1(darab1)
strpiece1 = Join(PieceArray1)
strpiece2 = Join(PieceArray2)
darab2 = darab2 + 1
Loop
CutToPieces = IIf(PartNo = 1, strpiece1, strpiece2)
End Function

Use it like this:

in cell u15
= CutToPieces(U13, 40, 1)
in cell u16
= CutToPieces(U13, 40, 2)

Regards,
Stefi


€˛norika€¯ ezt Ć*rta:


Stefi,
Thank your for help. I found that the UDF can count the length of
phrase except last word. Actually, the phrase is the payee printed in
cheque. If the length is too long, it will cut into two. From your UDF,
it only cuts out the last word.
Is there any ideas to solve it if the max length of 1st row is 40, more
than that it will write in 2nd row?

TIA
norika


--
norika
------------------------------------------------------------------------
norika's Profile: http://www.excelforum.com/member.php...fo&userid=4878
View this thread: http://www.excelforum.com/showthread...hreadid=496595