+ Reply to Thread
Results 1 to 10 of 10

Splitting comma delimted excel cell into multiple rows based on certain criteria

  1. #1
    Forum Contributor
    Join Date
    07-19-2017
    Location
    usa
    MS-Off Ver
    2016 Professional Plus
    Posts
    130

    Splitting comma delimted excel cell into multiple rows based on certain criteria

    Hi Everyone,
    I have attached an excel file which contains two sheets "Before" and "After" . I want to make change the data in "Before" sheet to "After" sheet. The data in excel column B which is comma delimited should be splitted into multiple rows and the data in column A should repeat itself accordingly. When you will open the file then you will easily understand it. Many thanks in advance for your help.

    Best Regards,
    Attached Files Attached Files

  2. #2
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    Please try at sheet "Before"

    D1

    =IFERROR(INDEX($A$1,(ROWS(B$1:B1)+LEN(B$1)-LEN(SUBSTITUTE(B$1,",","")))/(LEN(B$1)-LEN(SUBSTITUTE(B$1,",",""))+1)),"")

    E1

    =IFERROR(--MID(SUBSTITUTE(B$1,",",REPT(" ",LEN(B$1))),1+(ROWS(B$1:B1)-1)*LEN(B$1),LEN(B$1)),"")

  3. #3
    Forum Contributor
    Join Date
    07-19-2017
    Location
    usa
    MS-Off Ver
    2016 Professional Plus
    Posts
    130

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    Thanks for your reply. but here is a situation. The formulas have limitations that if there is similar data in column A and B in multiple rows then it won't work.In otherwords, the formulas you provided works for only row 1. I want a such formulas which could work for multiple rows.

  4. #4
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    Please see attached
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    07-19-2017
    Location
    usa
    MS-Off Ver
    2016 Professional Plus
    Posts
    130

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    Why is there some data in column C and D and the same columns have been used in formulas as well. Though the formulas are working fine but I am confused about column C and D.

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    C is for count comma +1
    D is helper column base on C

    D is needed for guide the G# so from G1-G4 is with A1 "a" and G5-G10 stay with A2 "B" and so on.

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2404
    Posts
    13,406

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    Piggy backing on Bo_Ry's upload:


    A
    B
    C
    D
    E
    F
    1
    a
    1,2,3,4
    4
    a
    1
    In column C: =SUM(INDEX(LEN($B$1:$B1)-LEN(SUBSTITUTE($B$1:$B1,",",""))+1,0))
    2
    b
    11,12,13,14,15,16
    10
    a
    2
    In column D: =IF(ROWS(D$1:D1)>MAX($C$1:$C$3),"",INDEX($A$1:$A$3,MATCH(0,INDEX(--(ROWS(D$1:D1)>$C$1:$C$3),0),0)))
    3
    C
    22,252,242,25,26
    15
    a
    3
    In column E: =IF(D1="","",TRIM(MID(SUBSTITUTE(INDEX($B$1:$B$3,MATCH(D1,$A$1:$A$3,0)),",",REPT(" ",99)),(COUNTIF($D$1:D1,D1)-1)*99+1,99)))
    4
    a
    4
    5
    b
    11
    6
    b
    12
    7
    b
    13
    8
    b
    14
    9
    b
    15
    10
    b
    16
    11
    C
    22
    12
    C
    252
    13
    C
    242
    14
    C
    25
    15
    C
    26
    Dave

  8. #8
    Forum Contributor
    Join Date
    10-30-2003
    Location
    Singapore
    MS-Off Ver
    Excel 2019
    Posts
    197

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    Or……………………………..

    Try this formula solution without helper

    1] Using FlameRetired's layout table

    2] In D1, copied down :

    =IFERROR(INDEX(A$1:A$3,AGGREGATE(15,6,ROW(A$1:A$3)/(LEN(B$1:B$3)-LEN(SUBSTITUTE(B$1:B$3,",",""))+1>=COLUMN($A:$J)),ROWS($1:1))),"")

    3] In E1, copied down :

    =IF(D1="","",TRIM(MID(SUBSTITUTE(","&VLOOKUP(D1,A$1:B$3,2,0),",",REPT(" ",99)),COUNTIF(D$1:D1,D1)*99,99)))

    Regards
    Bosco

  9. #9
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2404
    Posts
    13,406

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    @ Bosco

    I like your approach in the D1 formula.

    We've seen these kind of problems on the forums before. I am always on the lookout for alternatives to a helper columns and SUBTOTAL/OFFSET.

    Your formula looks promising. In the interest of making this more robust can you tell me how you arrived at the COLUMN($A:$J) part ... the logic? How might that be calculated?

    Edit Never mind I answered my own question.
    Last edited by FlameRetired; 10-07-2018 at 11:41 AM.

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,102

    Re: Splitting comma delimted excel cell into multiple rows based on certain criteria

    I moved the data onto the second row to allow for headers. This required a minor adjustment to Bosco's formula.

    I used a modification (in column G) of his original formula (in column C) to allow for strings longer than 10 comma-separated entries WITHOUT adjustments to the formula...

    Bosco's formula in column D is very clever!!
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Splitting Cell that contains multiple Headers with Data separated by comma.
    By omershafiq2012 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2014, 09:42 AM
  2. Macro splitting comma delimated cell text into rows with other row data copied...
    By geoffffffff in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2013, 11:07 AM
  3. [SOLVED] Splitting cell contents based on Comma and inserting new rows below it.
    By SS113 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-22-2013, 09:09 AM
  4. Save as Comma Delimted
    By Harlequin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-10-2011, 10:24 AM
  5. Sum values based on multiple criteria (comma delimited) in a single cell
    By leem888 in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 01-07-2011, 02:49 PM
  6. Replies: 3
    Last Post: 11-13-2009, 12:05 PM
  7. [SOLVED] CANNOT Import comma delimted, quote qualifed text file into Excel.
    By Feiming Chen in forum Excel General
    Replies: 1
    Last Post: 03-01-2006, 05:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1