@ Rick, I took the freedom to tweak your code to adjust the linebreaks.
Code:
Function WrapText(CellWithText As String, MaxChars) As String
Dim Space As Long, Text As String, TextMax As String
Dim vLine As Variant, i As Long
vLine = Split(CellWithText, Chr(10))
For i = 0 To UBound(vLine)
Text = vLine(i)
Do While Len(Text) > MaxChars
TextMax = Left(Text, MaxChars + 1)
If Right(TextMax, 1) = " " Then
WrapText = WrapText & RTrim(TextMax) & vbLf
Text = Mid(Text, MaxChars + 2)
Else
Space = InStrRev(TextMax, " ")
If Space = 0 Then
WrapText = WrapText & Left(Text, MaxChars) & vbLf
Text = Mid(Text, MaxChars + 1)
Else
WrapText = WrapText & Left(TextMax, Space - 1) & vbLf
Text = Mid(Text, Space + 1)
End If
End If
Loop
WrapText = WrapText & Text & Chr(10)
Next
WrapText = IIf(Right(WrapText, 1) = Chr(10), Left(WrapText, Len(WrapText) - 1), WrapText)
End Function
Bookmarks