[table="width: 500"]
[tr]
[td]Sub SplitTextOnSpacesWithMaxCharactersPerLine()
Dim Text As String, TextMax As String, SplitText As String, Answer() As String
Dim Space As Long, Source As Range, CellWithText As Range
Const MaxChars As Long = 40
Const DestinationOffset As Long = 1
Set Source = Range("A1", Cells(Rows.Count, "A").End(xlUp))
On Error GoTo 0
For Each CellWithText In Source
If Len(CellWithText) Then
Text = CellWithText.Value
SplitText = ""
Do While Len(Text) > MaxChars
TextMax = Left(Text, MaxChars + 1)
If Right(TextMax, 1) = " " Then
SplitText = SplitText & RTrim(TextMax) & vbLf
Text = Mid(Text, MaxChars + 2)
Else
Space = InStrRev(TextMax, " ")
If Space = 0 Then
SplitText = SplitText & Left(Text, MaxChars) & vbLf
Text = Mid(Text, MaxChars + 1)
Else
SplitText = SplitText & Left(TextMax, Space - 1) & vbLf
Text = Mid(Text, Space + 1)
End If
End If
Loop
Answer = Split(SplitText & Text, vbLf)
CellWithText.Offset(, DestinationOffset).Resize(, UBound(Answer) + 1).Value = Answer
End If
Next
End Sub[/td]
[/tr]
[/table]