Split text after every last whole word every 30 characters

user47

New Member
Joined
Apr 6, 2013
Messages
17
Office Version
  1. 365
Good day all,

I have address data that is unfortunately punctuated with line feed characters.

I need to split the data at every 30 characters.... but on the condition that the 30th character cannot be in the middle of a word. If it is, then only the last whole word before the 30th position can stay and the next word after that gets spilled over into the next column for the next 30 characters... on the condition that the 60th character cannot be in the middle of a word etc and so on. Is there any way to do this in excel? I have prepared an example below (manually) as best as I can but please feel free to let me know if any clarifications are needed as I know this may be a tricky one to word correctly for help.

Thanking you all in advance.


WorkBook1.xlsx
ABCDEF
130 characters max per column rounded down to last whole word
2Addresseach col has whole words only that fit under 30 characters per col
374850 Brightly Blazing Glory Days Long Road Candyland Avenue Four Interdimensional Galaxy Rift Sector Seventy Seven Point Six 74850 Brightly Blazing GloryDays Road Candyland AvenueFour Interdimensional GalaxyRift Sector Seventy SevenPoint Six
4Length of string28262825
Sheet2
Cell Formulas
RangeFormula
B4:E4B4=LEN(B3)
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
There's probably a cleverer way, but maybe:

Book1
ABCDEFGH
130 characters max per column rounded down to last whole word
2Addresseach col has whole words only that fit under 30 characters per col
374850 Brightly Blazing Glory Days Long Road Candyland Avenue Four Interdimensional Galaxy Rift Sector Seventy Seven Point Six 4850 Brightly Blazing GloryDays Long Road CandylandAvenue Four InterdimensionalGalaxy Rift Sector SeventySeven Point Six 
4Length of string27242826150
Sheet1
Cell Formulas
RangeFormula
C3:H3C3=LET(a,TRIM(SUBSTITUTE($A3,CHAR(10)," ")),b,MID(a,LEN(TEXTJOIN(" ",,$B3:B3))+2,LEN(a))&" ",s,SEQUENCE(30),TRIM(LEFT(b,MAX(IF(MID(b,s,1)=" ",s)))))
C4:H4C4=LEN(C3)
 
Last edited:
Upvote 0
Solution
There's probably a cleverer way, but maybe:

Book1
ABCDEFGH
130 characters max per column rounded down to last whole word
2Addresseach col has whole words only that fit under 30 characters per col
374850 Brightly Blazing Glory Days Long Road Candyland Avenue Four Interdimensional Galaxy Rift Sector Seventy Seven Point Six 4850 Brightly Blazing GloryDays Long Road CandylandAvenue Four InterdimensionalGalaxy Rift Sector SeventySeven Point Six 
4Length of string27242826150
Sheet1
Cell Formulas
RangeFormula
C3:H3C3=LET(a,TRIM(SUBSTITUTE($A3,CHAR(10)," ")),b,MID(a,LEN(TEXTJOIN(" ",,$B3:B3))+2,LEN(a))&" ",s,SEQUENCE(30),TRIM(LEFT(b,MAX(IF(MID(b,s,1)=" ",s)))))
C4:H4C4=LEN(C3)
Hello, good day Sir,

Thank you! You are amazing!!!!

This worked although when i tried it for the columns I needed it for, it missed the first character in the first column. I am still wrapping my tiny mind around how the formula works but i was able to use left() to fix the specific issue where it left out the first character. I suspect it has to do with maybe which column I am entering it relative to where the data is etc. No worries though, I can gladly use that fix as I try to wrap my novice mind around the glorious wit in your solution. Thanks again so much!
 
Upvote 0
This worked although when i tried it for the columns I needed it for, it missed the first character in the first column. I am still wrapping my tiny mind around how the formula works but i was able to use left() to fix the specific issue where it left out the first character. I suspect it has to do with maybe which column I am entering it relative to where the data is etc. No worries though, I can gladly use that fix as I try to wrap my novice mind around the glorious wit in your solution. Thanks again so much!

Small modification to Erik's formula:

=LET(a,TRIM(SUBSTITUTE($A3,CHAR(10)," ")),b,MID(a,LEN(TEXTJOIN(" ",,$B3:B3))+1,LEN(a))&" ",s,SEQUENCE(30),TRIM(LEFT(b,MAX(IF(MID(b,s,1)=" ",s)))))
 
Upvote 0
Small modification to Erik's formula:

=LET(a,TRIM(SUBSTITUTE($A3,CHAR(10)," ")),b,MID(a,LEN(TEXTJOIN(" ",,$B3:B3))+1,LEN(a))&" ",s,SEQUENCE(30),TRIM(LEFT(b,MAX(IF(MID(b,s,1)=" ",s)))))
Whoa! Thank you! That fixed it when applying it to my data set!

(Just to be clear Erik's solution worked fine with the example I initially gave but just with my dataset it was off by 1 character. Your modification works perfectly with the dataset.)

Thank you both!
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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