textsplit to next row with the same value in parallel row

ExcelNewbie2020

Active Member
Joined
Dec 3, 2020
Messages
343
Office Version
  1. 365
Platform
  1. Windows
how to textsplit column B by rows while keeping the value in column A?..thank you


Book1
ABCDE
1NAME1APPLE, BERRY, DOG, CATEXPECTED RESULT
2NAME2APPLE, BERRYNAME1APPLE
3NAME3APPLE, BERRY, CATNAME1BERRY
4NAME4BERRY, DOG, CATNAME1DOG
5NAME5APPLE, DOG, CATNAME1CAT
6NAME2APPLE
7NAME2BERRY
8NAME3APPLE
9NAME3BERRY
10NAME3CAT
11NAME4BERRY
12NAME4DOG
13NAME4CAT
14NAME5APPLE
15NAME5DOG
16NAME5CAT
17
18
19
20
21
Sheet3
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Power query
Book1
ABCDEFGH
1Column1Column2EXPECTED RESULT
2NAME1APPLE, BERRY, DOG, CATNAME1APPLEColumn1Value
3NAME2APPLE, BERRYNAME1BERRYNAME1APPLE
4NAME3APPLE, BERRY, CATNAME1DOGNAME1 BERRY
5NAME4BERRY, DOG, CATNAME1CATNAME1 DOG
6NAME5APPLE, DOG, CATNAME2APPLENAME1 CAT
7NAME2BERRYNAME2APPLE
8NAME3APPLENAME2 BERRY
9NAME3BERRYNAME3APPLE
10NAME3CATNAME3 BERRY
11NAME4BERRYNAME3 CAT
12NAME4DOGNAME4BERRY
13NAME4CATNAME4 DOG
14NAME5APPLENAME4 CAT
15NAME5DOGNAME5APPLE
16NAME5CATNAME5 DOG
17NAME5 CAT
Sheet3


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Column2.1", "Column2.2", "Column2.3", "Column2.4"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column2.1", type text}, {"Column2.2", type text}, {"Column2.3", type text}, {"Column2.4", type text}}),
    #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type1", {"Column2.1", "Column2.2", "Column2.3", "Column2.4"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Only Selected Columns",{"Attribute"})
in
    #"Removed Columns"
 
Upvote 0
Power query
Book1
ABCDEFGH
1Column1Column2EXPECTED RESULT
2NAME1APPLE, BERRY, DOG, CATNAME1APPLEColumn1Value
3NAME2APPLE, BERRYNAME1BERRYNAME1APPLE
4NAME3APPLE, BERRY, CATNAME1DOGNAME1 BERRY
5NAME4BERRY, DOG, CATNAME1CATNAME1 DOG
6NAME5APPLE, DOG, CATNAME2APPLENAME1 CAT
7NAME2BERRYNAME2APPLE
8NAME3APPLENAME2 BERRY
9NAME3BERRYNAME3APPLE
10NAME3CATNAME3 BERRY
11NAME4BERRYNAME3 CAT
12NAME4DOGNAME4BERRY
13NAME4CATNAME4 DOG
14NAME5APPLENAME4 CAT
15NAME5DOGNAME5APPLE
16NAME5CATNAME5 DOG
17NAME5 CAT
Sheet3


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Column2.1", "Column2.2", "Column2.3", "Column2.4"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column2.1", type text}, {"Column2.2", type text}, {"Column2.3", type text}, {"Column2.4", type text}}),
    #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type1", {"Column2.1", "Column2.2", "Column2.3", "Column2.4"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Only Selected Columns",{"Attribute"})
in
    #"Removed Columns"
thanks mate, but I'm not familiar with power query. I hope its possible using excel formula..
 
Upvote 0
Hi

=LET(X,A1:A10,Y,B1:B10,k,TOCOL(BYROW(Y,LAMBDA(s,ROWS(TEXTSPLIT(s,,", ")))),3),CHOOSE({1\2},TOCOL(IF(SEQUENCE(,MAX(k))<=k,X,W),3),FILTERXML("<t><s>"&TEXTJOIN("</s><s>",,SUBSTITUTE(Y,", ","</s><s>"))&"</s></t>","//s")))
 
Upvote 0
Solution
Hi
VBA
Try
VBA Code:
Sub test()
    Dim a, x
    Dim i&, ii&
    a = Cells(1).CurrentRegion
    For i = 1 To UBound(a)
        x = Split(a(i, 2), ",")
        Cells(2 + ii, 4).Resize(UBound(x) + 1) = Cells(i, 1)
        Cells(2 + ii, 5).Resize(UBound(x) + 1) = Application.Transpose(x)
        ii = ii + UBound(x) + 1
    Next
End Sub
 
Upvote 0
Hi

=LET(X,A1:A10,Y,B1:B10,k,TOCOL(BYROW(Y,LAMBDA(s,ROWS(TEXTSPLIT(s,,", ")))),3),CHOOSE({1\2},TOCOL(IF(SEQUENCE(,MAX(k))<=k,X,W),3),FILTERXML("<t><s>"&TEXTJOIN("</s><s>",,SUBSTITUTE(Y,", ","</s><s>"))&"</s></t>","//s")))
this worked replacing the backslash with a comma. thanks mate..
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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