Hope this works for you too. In the code fc is the first cell (now A1), lc is the last cell of the range (now A3), dst (now B1) is the cell where the split cells begin.
Sub splittxt()
Dim c As Range
Dim fc, lc, dst As String
Dim start, ostart, pstart As Long
fc = "a1"
lc = "a3"
dst = "b1"
Application.ScreenUpdating = False
For Each c In ActiveSheet.Range(fc, lc)
start = 1
pstart = 1
For i = 1 To Len(c)
ostart = start
start = InStr(start + 1, c, " ")
If start - pstart > 40 Then
c = Application.WorksheetFunction.Replace(c, InStrRev(c, " ", pstart + 40), 1, "#")
start = ostart
pstart = ostart
End If
Next
Next
Application.DisplayAlerts = False
Range(fc, lc).Select
Selection.TextToColumns Destination:=Range(dst), DataType:=xlDelimited, other:=True, otherchar:="#"
Application.DisplayAlerts = True
Selection.Replace what:="#", replacement:=" "
Application.ScreenUpdating = True
End Sub
Bookmarks