Split String from Right

Blessy Clara

Board Regular
Joined
Mar 28, 2010
Messages
201
Hi

There are about 10,000 rows of address

Sample
[TABLE="width: 423"]
<colgroup><col></colgroup><tbody>[TR]
[TD]243 River Street Ballina[/TD]
[/TR]
[TR]
[TD]Bundaberg[/TD]
[/TR]
[TR]
[TD]Dunsborough[/TD]
[/TR]
[TR]
[TD]Suite 5 Kawana Prof Cnt 134A Pt Cartwright Drive Buddina[/TD]
[/TR]
[TR]
[TD]Suite 3/170 Gooding Drive Merrimac[/TD]
[/TR]
[TR]
[TD]1 Bangalow Road Ballina[/TD]
[/TR]
[TR]
[TD]921 Station St, Box Hill North[/TD]
[/TR]
[TR]
[TD]112 Drummond Street North, Ballarat[/TD]
[/TR]
[TR]
[TD] [TABLE="width: 347"]
<tbody>[TR]
[TD="class: xl68, width: 347"]173 Hampton Street, Bridge town

[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
Requirement - Want to split the string from Right

with the First space for those without coma
[TABLE="width: 487"]
<tbody>[TR]
[TD="class: xl68, width: 423"]243 River Street [/TD]
[TD="width: 64"]Ballina[/TD]
[/TR]
</tbody>[/TABLE]

and for those records with coma it should be the first occurrence of coma from right
112 Drummond Street North Ballarat
[TABLE="width: 347"]
<tbody>[TR]
[TD="class: xl68, width: 347"]173 Hampton Street Bridge town[/TD]
[/TR]
</tbody>[/TABLE]
Those highlighted in Red to be split to next columns

Using Text to column or Formula may not be helpful as the count/length of string varies

Thank you
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 423"]
<tbody>[TR]
[TD="class: xl68, width: 423"]243 River Street[/TD]
[/TR]
[TR]
[TD="class: xl68, width: 423"][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Ballina[/TD]
[/TR]
[TR]
[TD][TABLE="width: 423"]
<tbody>[TR]
[TD="class: xl68, width: 423"]112 Drummond Street North[/TD]
[/TR]
[TR]
[TD="class: xl68, width: 423"][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 423"]
<tbody>[TR]
[TD="class: xl68, width: 423"]Ballarat[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 423"]
<tbody>[TR]
[TD="class: xl68, width: 423"]Suite 3/170 Gooding Drive [/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Merrimac[/TD]
[/TR]
</tbody>[/TABLE]

Hi Thank you, but the purpose is to split suburb from address as above,

the formula fetches the term though.

[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 423"]
<tbody>[TR]
[TD="class: xl68, width: 423"]243 River Street Ballina[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Ballina[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Then use a formula like this
=SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))

to replace the last space with ~,
Then use TextToColumns to split with a ~ delimiter.
Note that the last screen of the TextToColumns dialog has a Destination that can be used to write the split data over the old location.
 
Upvote 0
[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 337"]
<tbody>[TR]
[TD="class: xl66, width: 337"]1 Intrepid Dr, Victoria [/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]1 Intrepid Dr[/TD]
[TD]Victoria [/TD]
[/TR]
[TR]
[TD]1 Leghorn St Rockingham[/TD]
[TD]1 Leghorn St[/TD]
[TD]Rockingham[/TD]
[/TR]
[TR]
[TD]173 Oxley Avenue, Woody Point
[/TD]
[TD]173 Oxley Avenue [/TD]
[TD]Woody Point[/TD]
[/TR]
[TR]
[TD]Post Formula[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 337"]
<tbody>[TR]
[TD="class: xl66, width: 337"]1 Intrepid Dr, Victoria Point[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 337"]
<tbody>[TR]
[TD="class: xl66, width: 337"]1 Intrepid Dr, Victoria[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Point[/TD]
[/TR]
[TR]
[TD]1 Leghorn St Rockingham[/TD]
[TD]1 Leghorn St [/TD]
[TD]Rockingham[/TD]
[/TR]
[TR]
[TD]206 Stirling Hwy, Brighton


[/TD]
[TD]206 Stirling Hwy, [/TD]
[TD]Brighton[/TD]
[/TR]
[TR]
[TD]173 Oxley Avenue, Woody Point[/TD]
[TD]173 Oxley Avenue, Woody [/TD]
[TD]Point[/TD]
[/TR]
</tbody>[/TABLE]

Sorry - but i am left with two concerns

a coma at the end for those records that had coma as criteria - and when there are two words after coma only one word is split
 
Last edited:
Upvote 0
So the rule is
If no comma, split at last space
otherwise, split at last comma.

correct?
 
Last edited:
Upvote 0
I'm at work and can't put it together right now, but I'd have one column with

=IF(LEN(A1)=LEN(SUBSTITUTE(A1,",",""), replace last space with ", ", A1)

then another helper column with a "replace last , with ~" formula, and then use TextToColumns

Those "replace last.." formulas would look like the formula above.
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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