Break up text in a single cell into separate cells with limited text length

SUNNY ISLAND

New Member
Joined
Nov 1, 2006
Messages
13
I have the following text in cell A1

HUNDRED TREES, 87 WEST COASTAL DRIVE, #12-10, HONG KONG 128015

I would like to break up the text to cells A2 and A3 and each cell can take only text length up to 40

Can this be done via WS formula instead of VBA?

THANKS
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
@ Istvan
Something in your post messed up the thread so that no Reply button was available so I have removed your post.
You may want to try again, though I did get the gist of what you were getting at.
I had considered the first issue you raised but decided the likelihood of such was so remote as to not bother. The second issue I had not considered but will have a think about that.
 
Upvote 0
Two issues about my suggestion were raised by István Hirsch:

Hi Peter,
I had suggested a similar approach before but now I am trying to find another approach as the very low probability of repeating the same string in the text will stop processing because the first occuration of the repeated string will be always found, for example here:
I am the delegate of the Association: welcome to all the participants of the Conference on Stress Corrosion. Also, welcome to all the participants of the Symposium held at the same time on the same problem here …
Given that this OP's data appears to be addresses, I think the likelihood of of an approximately 40-character string occurring at just the right place to form the contents of one of the result cells and also re-occur at another point in the original text is remote enough to ignore.


More important: as the length of the strings to process is not known before processing, the formula should be copied down according to the longest expected string. If the substring in the last row of a string (which is not the longest expected) is found in the text above the last row, the text following that substring will be processed again
This was a valid point and the example is below, showing how my suggested formulas did not produce the correct results.

Excel Workbook
A
1HUNDRED TREES AREA, 87 WEST COASTAL DRIVE, #12-10, HONG KONG 128015, HONG KONG
2HUNDRED TREES AREA, 87 WEST COASTAL
3DRIVE, #12-10, HONG KONG 128015, HONG
4KONG
5128015, HONG KONG
6
Split Text (3)



Again, given that we appear to be dealing with address-type data, and breaking it into longish (approx 40 character) chunks, I think the following modification to the A3 (& copied down) formula may suffice.

Excel Workbook
A
1HUNDRED TREES AREA, 87 WEST COASTAL DRIVE, #12-10, HONG KONG 128015, HONG KONG
2HUNDRED TREES AREA, 87 WEST COASTAL
3DRIVE, #12-10, HONG KONG 128015, HONG
4KONG
5
6
Split Text (2)
 
Upvote 0
Thanks for correcting my post, Peter. Something went wrong during pasting, and the button of post-editing also disappeared.

I have tried another method. The string to process is in A1, A2 is to be left blank, the formula below should be copied in A3, confirmed with Ctrl + Shift + Enter and copied down:
Excel Workbook
AB
1The awards ceremony was first broadcast to radio in 1930 and televised in 1953. It is now seen live in more than 200 countries and can be streamed live online.[3] The Oscars is the oldest entertainment awards ceremony; its equivalents, the Emmy Awards for television, the Tony Awards for theatre, and the Grammy Awards for music and recording, are modeled after the Academy Awards.LENGTH
2
3The awards ceremony was first broadcast39
4to radio in 1930 and televised in 1953.39
5It is now seen live in more than 20036
6countries and can be streamed live34
7online.[3] The Oscars is the oldest35
8entertainment awards ceremony; its34
9equivalents, the Emmy Awards for32
10television, the Tony Awards for theatre,40
11and the Grammy Awards for music and35
12recording, are modeled after the Academy40
13Awards.7
140
Sheet
 
Upvote 0
Assuming the original text does not include and double, triple etc spaces, then try ..
In A2: =LEFT(A1,40-LEN(TRIM(RIGHT(SUBSTITUTE(LEFT(A1,41)," ",REPT(" ",100)),100))))
In A3 and copy down: =IF(A2="","",TRIM(LEFT(MID(A$1,FIND(A2,A$1)+LEN(A2)+1,LEN(A$1)),40-LEN(TRIM(RIGHT(SUBSTITUTE(LEFT(MID(A$1,FIND(A2,A$1)+LEN(A2)+1,LEN(A$1)),41)," ",REPT(" ",100)),100))))))

Just a guess (not tested!): the issue of finding the substring (left for the last row) in the body of the text can be eliminated by adding a special character to the end of the text in A1 (for example „A1 & „ß”), then this substring will not be found in the body of the text during processing, resulting the correct working of the formula. Of course, then „ß” should be deleted.
 
Last edited:
Upvote 0
I think the following modifications should allow for all circumstances, including a very common repeated pattern.

Formula in A2 is copied across.
Formula in A3 is copied across and down.

Excel Workbook
AB
1HUNDRED TREES AREA, 87 WEST COASTAL DRIVE, #12-10, HONG KONG 128015, HONG KONGabcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd
2HUNDRED TREES AREA, 87 WEST COASTALabcd abcd abcd abcd abcd abcd abcd abcd
3DRIVE, #12-10, HONG KONG 128015, HONGabcd abcd abcd abcd abcd abcd abcd abcd
4KONGabcd abcd abcd abcd abcd abcd abcd abcd
5abcd abcd abcd abcd abcd
6
Split Text (5)




If we left row 2 blank (& possibly hidden) then this single formula, copied across & down could be used as far as I can see.

Excel Workbook
AB
1HUNDRED TREES AREA, 87 WEST COASTAL DRIVE, #12-10, HONG KONG 128015, HONG KONGabcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd
3HUNDRED TREES AREA, 87 WEST COASTALabcd abcd abcd abcd abcd abcd abcd abcd
4DRIVE, #12-10, HONG KONG 128015, HONGabcd abcd abcd abcd abcd abcd abcd abcd
5KONGabcd abcd abcd abcd abcd abcd abcd abcd
6abcd abcd abcd abcd abcd
7
Split Text (6)
 
Upvote 0
The formula in my post #15 needs correcting:

=IF(LEN(A$1)-SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3<41,TRIM(MID(A$1,SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3,LEN(A$1)-SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3)),TRIM(LEFT(REPLACE(A$1,1,SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3,""),42-MATCH(TRUE,MID(MID(REPLACE(A$1,1,SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3,""),1,42),42-ROW($1:$40),1)=" ",0))))
 
Upvote 0
The formula in my post #15 needs correcting:

=IF(LEN(A$1)-SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3<41,TRIM(MID(A$1,SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3,LEN(A$1)-SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3)),TRIM(LEFT(REPLACE(A$1,1,SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3,""),42-MATCH(TRUE,MID(MID(REPLACE(A$1,1,SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3,""),1,42),42-ROW($1:$40),1)=" ",0))))

It needs correcting again:

=IF(LEN(A$1)-SUM(LEN(A$2:A2))-ROWS(A$1:A3)+3<41,RIGHT(A$1,LEN(A$1)-SUM(LEN(A$2:A2))-ROWS(A$1:A3)+3),TRIM(LEFT(REPLACE(A$1,1,SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3,""),42-MATCH(TRUE,MID(MID(REPLACE(A$1,1,SUM(LEN(A$2:A2))+ROWS(A$1:A3)-3,""),1,42),42-ROW($1:$40),1)=" ",0))))
 
Upvote 0
It needs correcting again:
István

- For me it returns #VALUE once it runs out of text to evaluate. eg A6 & below for "HUNDRED TREES AREA, 87 WEST COASTAL DRIVE, #12-10, HONG KONG 128015, HONG KONG"

- Do you see a circumstance where my considerably shorter & non-array-entered formula from the bottom part of post #17 would not work?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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