Convert list with commas and spaces in single cell, into list in separate rows - Assistance

Quiinn

New Member
Joined
Jun 23, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I'm looking to convert an entire column within a spreadsheet, to ensure each cell containing a list is converted into rows underneath with single postcodes as per the example below.
I wasn't sure if there was a function or a formula I could use to execute this.

Any help would be much appreciated!

All I need is to take all of the data in column B and extend it to only feature one district code in each cell.

E.g,



Postcode areaPostcode districtsPost TownFormer postal county
EXEX1, EX2, EX3, EX4, EX5, EX6ExeterDevon


To instead be listed as;



Postcode areaPostcode districtsPost TownFormer postal county
EXEX1ExeterDevon
EXEX2ExeterDevon
EXEX3ExeterDevon
EXEX4ExeterDevon
EXEX5ExeterDevon

Many thanks,
Q
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
This got ugly fast. I presume that you wanted to handle multiple rows of inputs. It only works right if the postcodes are always three characters separated by a comma-space. If it's going to go to EX10 or more, I'll have to think of something.

MrExcelPlayground18.xlsx
ABCDEFGHI
1Post AreaCodesTownFormer CountyPost AreaCodesTownFormer County
2EXEX1, EX2, EX3, EX4, EX5, EX6ExeterDevonEXEX1ExeterDevon
3JAJA1, JA2, JA3JambovilleGoosetownEXEX2ExeterDevon
4BOBO1, BO2, BO3, BO4BozotonClownvilleEXEX3ExeterDevon
5EXEX4ExeterDevon
6EXEX5ExeterDevon
7EXEX6ExeterDevon
8JAJA1JambovilleGoosetown
9JAJA2JambovilleGoosetown
10JAJA3JambovilleGoosetown
11BOBO1BozotonClownville
12BOBO2BozotonClownville
13BOBO3BozotonClownville
14BOBO4BozotonClownville
Sheet6
Cell Formulas
RangeFormula
F2:I14F2=LET(w,A2:A4,x,B2:B4,y,C2:C4,z,D2:D4,a,LEN(x)-LEN(SUBSTITUTE(x,",",""))+1,b,MAKEARRAY(ROWS(a),ROWS(a),LAMBDA(r,c,IF(r>=c,1,0))),c,TRANSPOSE(MMULT(b,a)),d,SEQUENCE(SUM(a)),e,IF(d<=c,d,0),f,HSTACK(SEQUENCE(ROWS(d),1,0,0),DROP(e,,-1)),g,e-BYCOL(f,LAMBDA(array,MAX(array))),h,BYROW(g,LAMBDA(array,MAX(array))),ee,IF(d<=c,1,0),eee,1+ROWS(w)-MMULT(ee,SEQUENCE(ROWS(w),1,1,0)),n,INDEX(x,eee),o,MID(n,5*(h-1)+1,3),q,o,m,HSTACK(INDEX(w,eee),q,INDEX(y,eee),INDEX(z,eee)),m)
Dynamic array formulas.
 
Upvote 0
This is better for the variable length Codes:

MrExcelPlayground18.xlsx
ABCDEFGHI
1Post AreaCodesTownFormer CountyPost AreaCodesTownFormer County
2EXEX1, EX2, EX3, EX4, EX5, EX6ExeterDevonEXEX1ExeterDevon
3JAJA1, JA11, JA3JambovilleGoosetownEXEX2ExeterDevon
4BOBO1, BO2, BO3, BO4BozotonClownvilleEXEX3ExeterDevon
5EXEX4ExeterDevon
6EXEX5ExeterDevon
7EXEX6ExeterDevon
8JAJA1JambovilleGoosetown
9JAJA11JambovilleGoosetown
10JAJA3JambovilleGoosetown
11BOBO1BozotonClownville
12BOBO2BozotonClownville
13BOBO3BozotonClownville
14BOBO4BozotonClownville
Sheet6
Cell Formulas
RangeFormula
F2:I14F2=LET(w,A2:A4,x,B2:B4,y,C2:C4,z,D2:D4,a,LEN(x)-LEN(SUBSTITUTE(x,",",""))+1,b,MAKEARRAY(ROWS(a),ROWS(a),LAMBDA(r,c,IF(r>=c,1,0))),c,TRANSPOSE(MMULT(b,a)),d,SEQUENCE(SUM(a)),e,IF(d<=c,d,0),f,HSTACK(SEQUENCE(ROWS(d),1,0,0),DROP(e,,-1)),g,e-BYCOL(f,LAMBDA(array,MAX(array))),h,BYROW(g,LAMBDA(array,MAX(array))),ee,IF(d<=c,1,0),eee,1+ROWS(w)-MMULT(ee,SEQUENCE(ROWS(w),1,1,0)),n,INDEX(x,eee),o,IF(h=1,n,TEXTAFTER(n,", ",h-1)),p,LEFT(o,IFERROR(SEARCH(", ",o),99)-1),m,HSTACK(INDEX(w,eee),p,INDEX(y,eee),INDEX(z,eee)),m)
Dynamic array formulas.
 
Upvote 0
Another option
Excel Formula:
=LET(rs,BYROW(B2:B4,LAMBDA(br,ROWS(TEXTSPLIT(br,,",")))),HSTACK(TOCOL(IF(SEQUENCE(,MAX(rs))<=rs,A2:A4,1/0),2),DROP(REDUCE("",B2:B4,LAMBDA(x,y,VSTACK(x,TRIM(TEXTSPLIT(y,,","))))),1),TOCOL(IF(SEQUENCE(,MAX(rs))<=rs,C2:C4,1/0),2),TOCOL(IF(SEQUENCE(,MAX(rs))<=rs,D2:D4,1/0),2)))
 
Upvote 0
This got ugly fast. I presume that you wanted to handle multiple rows of inputs. It only works right if the postcodes are always three characters separated by a comma-space. If it's going to go to EX10 or more, I'll have to think of something.

MrExcelPlayground18.xlsx
ABCDEFGHI
1Post AreaCodesTownFormer CountyPost AreaCodesTownFormer County
2EXEX1, EX2, EX3, EX4, EX5, EX6ExeterDevonEXEX1ExeterDevon
3JAJA1, JA2, JA3JambovilleGoosetownEXEX2ExeterDevon
4BOBO1, BO2, BO3, BO4BozotonClownvilleEXEX3ExeterDevon
5EXEX4ExeterDevon
6EXEX5ExeterDevon
7EXEX6ExeterDevon
8JAJA1JambovilleGoosetown
9JAJA2JambovilleGoosetown
10JAJA3JambovilleGoosetown
11BOBO1BozotonClownville
12BOBO2BozotonClownville
13BOBO3BozotonClownville
14BOBO4BozotonClownville
Sheet6
Cell Formulas
RangeFormula
F2:I14F2=LET(w,A2:A4,x,B2:B4,y,C2:C4,z,D2:D4,a,LEN(x)-LEN(SUBSTITUTE(x,",",""))+1,b,MAKEARRAY(ROWS(a),ROWS(a),LAMBDA(r,c,IF(r>=c,1,0))),c,TRANSPOSE(MMULT(b,a)),d,SEQUENCE(SUM(a)),e,IF(d<=c,d,0),f,HSTACK(SEQUENCE(ROWS(d),1,0,0),DROP(e,,-1)),g,e-BYCOL(f,LAMBDA(array,MAX(array))),h,BYROW(g,LAMBDA(array,MAX(array))),ee,IF(d<=c,1,0),eee,1+ROWS(w)-MMULT(ee,SEQUENCE(ROWS(w),1,1,0)),n,INDEX(x,eee),o,MID(n,5*(h-1)+1,3),q,o,m,HSTACK(INDEX(w,eee),q,INDEX(y,eee),INDEX(z,eee)),m)
Dynamic array formulas.

Thanks James, unfortunately it's just giving me a SPILL error despite trying both formula's you provided.
 
Upvote 0
Make sure that all cells below & to the right of the formula are totally empty & then try the formula again.
 
Upvote 0
One more formula for you to try...
Excel Formula:
=VSTACK(A1:D1,TEXTSPLIT(TEXTJOIN(", ",,MAP(A2:A4,B2:B4,C2:C4,D2:D4,LAMBDA(a,b,c,d,a&"/"&SUBSTITUTE(b,", ","/"&c&"/"&d&", "&a&"/")&"/"&c&"/"&d))),"/",", "))
Note: If you have a lot of rows to process, this will probably fail to work because of length limitations in TEXTJOIN.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
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