Sub Demo1()
Dim S$(), P&, N&, L&
S = Split([A2].Value2)
P = Len(S(0))
For N = 1 To UBound(S)
L = Len(S(N))
P = P + 1 + L
If P > 30 Then P = L: S(0) = S(0) & vbLf & S(N) Else S(0) = S(0) & " " & S(N)
Next
[D2].Value2 = S(0)
End Sub
Sub Demo1vf()
Dim S$(), P&, C&, N&, L&
S = Split([A2].Value2)
P = Len(S(C))
For N = 1 To UBound(S)
L = Len(S(N))
P = P + 1 + L
If P > 30 Then C = C + 1: P = L: S(C) = S(N) Else S(C) = S(C) & " " & S(N)
Next
ReDim Preserve S(C)
[D2].Value2 = Join(S, vbLf)
End Sub
Actually i have to copy this text and put it in our company program when i copy and paste this text then it is showing complete text without line break , for instance i copy this text and put it in notepad no difference.
Thank you so much with this code my query is solved.Juzar22, according to your attachment a beginner starter demonstration, result in cell D2 :Code:Sub Demo1() Dim S$(), P&, N&, L& S = Split([A2].Value2) P = Len(S(0)) For N = 1 To UBound(S) L = Len(S(N)) P = P + 1 + L If P > 30 Then P = L: S(0) = S(0) & vbLf & S(N) Else S(0) = S(0) & " " & S(N) Next [D2].Value2 = S(0) End Sub
Do you like it ? So thanks to click on bottom right Like !
Function LimitCharacter(txt As String)
With CreateObject("VBScript.RegExp")
.Global = True
txt = Application.Trim(Replace(txt, vbLf, " "))
.Pattern = "(.{1,30})( |$)"
txt = .Replace(txt, "$1" & vbLf)
.Pattern = "\n+(?!.)"
LimitCharacter = .Replace(txt, "")
End With
End Function
Sorry i will take note of your advice !!Juzar22
Actually You should know all needed details BEFORE you could open a new thread.
You're still changing Your thread.