Separating inconsistent address information into columns

bornsteij78

New Member
Joined
Sep 29, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

I need to separate address information into 5 columns. Some of the addresses have 4 separators, and some have 3.

Address
1 Main St, Watertown, MA, 02472
8 Main St, #2, Watertown, MA, 02472

When I do text to columns, using "," as a separator, this is what happens:

1664470393416.png


How can I most efficiently get all these addresses to do this:
Address 1Address 2CityStateZip
1 Main StWatertownMA02472
8 Main St#2WatertownMA02472

Any help/guidance would be much appreciated.

Thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Working with addresses is always hard.

This uses filterxml until textsplit comes out. If there are four items, it will assume there is no Line 2 of the address.

MrExcelPlayground12.xlsx
ABCDEF
1AddressLine 1Line 2CityStateZip
21 Main St, Watertown, MA, 024721 Main StWatertownMA02472
38 Main St, #2, Watertown, MA, 024728 Main St#2WatertownMA02472
Sheet12
Cell Formulas
RangeFormula
B2:F3B2=LET(a,FILTERXML("<a><s>" &SUBSTITUTE(A2,",","</s><s>") & "</s></a>","//s"),b,ROWS(a),zip,INDEX(a,b),state,INDEX(a,b-1),city,INDEX(a,b-2),L,INDEX(a,1),LL,IF(b=4,"",INDEX(a,2)),CHOOSE(SEQUENCE(1,5),L,LL,city,state,zip))
Dynamic array formulas.
 
Upvote 0
Solution
=LET(a,FILTERXML("<a><s>" &SUBSTITUTE(A2,",","</s><s>") & "</s></a>","//s"),b,ROWS(a),zip,INDEX(a,b),state,INDEX(a,b-1),city,INDEX(a,b-2),L,INDEX(a,1),LL,IF(b=4,"",INDEX(a,2)),CHOOSE(SEQUENCE(1,5),L,LL,city,state,zip))
You rock, thanks so much!!
 
Upvote 0
If you have the new functions, another option
Fluff.xlsm
ABCDEF
1AddressLine 1Line 2CityStateZip
21 Main St, Watertown, MA, 024721 Main St Watertown MA02472
38 Main St, #2, Watertown, MA, 024728 Main St #2 Watertown MA02472
Main
Cell Formulas
RangeFormula
B2:F3B2=LET(a,TEXTSPLIT(A2,","),IF(COLUMNS(a)=4,CHOOSECOLS(EXPAND(a,,5,""),1,-1,2,3,4),a))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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