Insert a special character every X characters in a text cell

intercameleon

New Member
Joined
Feb 18, 2011
Messages
3
Hello,

I am having difficulty with the following problem:

I have in column A 150 rows of text containing between 4 and 80 words (20 to 300 characters or so) and I need to insert /n every 80 characters without cutting words.

For example:

Cell A1
Hello my name is peter. I am married and have three kids. I work as a postman and enjoy meeting new people.

this should become something like:

Hello my name is peter. I am married and have three kids. I work /n as a postman and enjoy meeting new people.



The use of a simple text-to-column would permit me to reconstruct (using =A1&" "&B1...) the phrase and insert /n every X words but wouldn't take into consideration the number of characters (which is a problem).

If anyone knows a macro or formula that could help, I would much appreciate it.

Thanks,

Mike
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hello,

Ok so I have also found the solution of =substitute(A1," "," /n ",X words) but the problem again is that the number of characters is not taken into consideration...

Still haven't got a solution, can anyone help?

Thanks !
 
Upvote 0
Try this:-
For data in column "A".
Code:
[COLOR="Navy"]Sub[/COLOR] MG18Feb56
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] oStg
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] num [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] nRay()
[COLOR="Navy"]Dim[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & rows.Count).End(xlUp))
  [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    num = 80
        c = 0
            Ray = Split(Dn, " ")
[COLOR="Navy"]For[/COLOR] n = 0 To UBound(Ray)
    oStg = oStg & Ray(n) & " "
        ReDim Preserve nRay(c)
            nRay(c) = Ray(n)
                 c = c + 1
     [COLOR="Navy"]If[/COLOR] Len(oStg) > num [COLOR="Navy"]Then[/COLOR]
       num = num + 80
         ReDim Preserve nRay(c)
           nRay(c) = "n/"
             c = c + 1
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
Dn = Join(nRay, " ")
 oStg = ""
  num = 0
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,981
Messages
6,128,091
Members
449,418
Latest member
arm56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top