+ Reply to Thread
Results 1 to 21 of 21

Splitting a list of values in separate columns

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    8

    Splitting a list of values in separate columns

    I am trying to put something together on Excel and I wanted to get input from the community.

    1. In my first column(Let's call it "input"), there will be a variety of values from 1-10 which will appear in cells as 1,7,10 or 4,5,6,7 or any other similar variation. The quantity of numbers can vary and will always be comma delimited.
    2. Following the first column are 10 additional columns. For simplicity, let's say they're labelled 1-10.
    3. If 2,5,6,9 is present in the first cell, I want the number 1 in the columns labelled 2,5,6 and 9.
    If 1,4 is present in the first cell, I want the number 1 in the columns labelled 1 and 4.

    The input will only be in the first cell so I am hoping to find a way to automate the placement of 1's in the appropriate column depending on the input in the first column("input").

    As a bonus, I'd like all cells not present in the first column to appear as a "0".

    Any suggestions, ideas or nudges in the right direction will be appreciated.
    Last edited by siouxfire; 05-08-2014 at 11:14 AM.

  2. #2
    Registered User
    Join Date
    01-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Splitting a list of values in separate columns

    Hey mate,

    Is this what you're looking for? Let me know if I mis-interpreted what you meant.

    Edit: If you want more cells, just highlight B2:K2 and drag the formulas down as far as you want.

    FYI the code I used was:
    =IF(ISERROR(SEARCH(B$1,$A2,1) ),"0",$B$1)
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    05-08-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Splitting a list of values in separate columns

    That's beautiful. Thank you. Would you be able to talk me through the process?

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

    Re: Splitting a list of values in separate columns

    Reapz,

    I was playing with this too. There's a problem with your solution (that I haven't got round yet, either). If there's no number 1, but there is a 10 in the string, your formula thinks that there's a 1 there.
    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

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

    Re: Splitting a list of values in separate columns

    This is a bit of a cheat, but it works. Anyone have a better idea?? (The cheat is the comma after the 1 in cell B1)
    Attached Files Attached Files

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Splitting a list of values in separate columns

    Need more info. Better if you upload a sample workbook with expected output filled manually and explaining that why do you expect that output in the sheet itself. That will help us to know your requirement.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  7. #7
    Registered User
    Join Date
    05-08-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Splitting a list of values in separate columns

    Yes, that's the only issue. Going beyond 10 causes some confusion. I'll look through the formulas and get a grip of them and I'm sure I'll find a solution to that. Thanks you again.

  8. #8
    Registered User
    Join Date
    05-08-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Splitting a list of values in separate columns

    For what I require, that "cheat" isn't a cheat. Thank you.

  9. #9
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Splitting a list of values in separate columns

    Hello Sioux ! Assuming your data i.e. 1,2,5,10 is in A2 and B1 to K1 is numbered as 1 to 10 then

    in b2 copy paste below
    =SUMPRODUCT(--(TRIM(MID(SUBSTITUTE(","&$A2,",",REPT(" ",100)),100*(ROW(INDIRECT("1:"&LEN($A2)-LEN(SUBSTITUTE($A2,",",""))+1))),100))+0=B$1))
    drag down and drag to left.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  10. #10
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Splitting a list of values in separate columns

    Hello Sioux ! Assuming your data i.e. 1,2,5,10 is in A2 and B1 to K1 is numbered as 1 to 10 then

    in b2 copy paste below
    =SUMPRODUCT(--(TRIM(MID(SUBSTITUTE(","&$A2,",",REPT(" ",100)),100*(ROW(INDIRECT("1:"&LEN($A2)-LEN(SUBSTITUTE($A2,",",""))+1))),100))+0=B$1))
    drag down and drag to left.


    if you don't want 0 to take place then use
    =if(SUMPRODUCT(--(TRIM(MID(SUBSTITUTE(","&$A2,",",REPT(" ",100)),100*(ROW(INDIRECT("1:"&LEN($A2)-LEN(SUBSTITUTE($A2,",",""))+1))),100))+0=B$1))=0,"",SUMPRODUCT(--(TRIM(MID(SUBSTITUTE(","&$A2,",",REPT(" ",100)),100*(ROW(INDIRECT("1:"&LEN($A2)-LEN(SUBSTITUTE($A2,",",""))+1))),100))+0=B$1)))
    Attached Files Attached Files
    Last edited by hemesh; 05-08-2014 at 11:54 AM.

  11. #11
    Registered User
    Join Date
    05-08-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Splitting a list of values in separate columns

    Thank you, I think that works. Trying it now.

    EDIT: That is excellent. Thank you, Hamesh. It's going to take me a while to work through your formula but it seems robust and works well above 10 as far as I can tell.
    Last edited by siouxfire; 05-08-2014 at 11:59 AM.

  12. #12
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Splitting a list of values in separate columns

    Hi,

    Welcome to the forum

    See the attached workbook for a macro....

    Sub SplitData()
    Dim rC As Range
    Dim x As Long
    Dim i As Long
    Dim a As Long
    Dim c As Long
        
        Application.ScreenUpdating = False
        c = Range("A" & Rows.Count).End(xlUp).Row
        For Each rC In Range("A2:A" & c).Cells
            x = Len(rC.Value) - Len(Replace(rC.Value, ",", ""))
            For i = 1 To x + 1
                a = Split(rC.Value, ",")(i - 1)
                Cells(rC.Row, a + 1).Value = 1
            Next i
        Next rC
        On Error Resume Next
        Range("A1").CurrentRegion.SpecialCells(xlCellTypeBlanks).Value = 0
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Last edited by RudiS; 05-08-2014 at 12:10 PM.
    Regards,
    Rudi

  13. #13
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Splitting a list of values in separate columns

    I think your cells are formatted as text. Try changing formatting to general or to number. then input the formula again

  14. #14
    Registered User
    Join Date
    05-08-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Splitting a list of values in separate columns

    Hemesh,

    I'm trying to work through how this is working but I'm having some difficulty and I've not been able to untangle this. Would you be able to explain a little of the logic behind the functions you've employed. For example, I'm a little mystified by why REPT(" ",100) is in there and how it works with SUBSTITUTE. Is that not in place of where the instance number should be for SUBSTITUTE?

    Many thanks.

  15. #15
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Splitting a list of values in separate columns

    You are welcome Sioux and Thanks for the feedback.
    Glad I could help

  16. #16
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Splitting a list of values in separate columns

    Out of interest, did you try the macro i posted.
    The macro will not have any issues with the length of the number. It uses the commas to split the data per column.

  17. #17
    Registered User
    Join Date
    05-08-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Splitting a list of values in separate columns

    Yes, I did try the macro and it works beautifully. I was planning on looking at that in more detail once I'd got my head around Hemesh's solution.

  18. #18
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Splitting a list of values in separate columns

    No worries...just asking for interest sake
    The great thing about forums is that you get various solutions and as the initiator, you can pick and choose from them at your will.

    Cheers

  19. #19
    Registered User
    Join Date
    05-08-2014
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Splitting a list of values in separate columns

    To be honest, I'm not familiar with macros but you've given me the motivation to do so. On the surface, it looks easier to grasp.

  20. #20
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Splitting a list of values in separate columns

    Excel formulas are extremely powerful and flexible, esp. those in the array group, but sometimes macros can make things much easier; especially when you need multiple nests in array formulas.

  21. #21
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Splitting a list of values in separate columns

    NO it is not there in the instance number of substitute,
    =SUMPRODUCT(--(TRIM(MID(SUBSTITUTE(","&$A2,",",REPT(" ",100)),100*(ROW(INDIRECT("1:"&LEN($A2)-LEN(SUBSTITUTE($A2,",",""))+1))),100))+0=B$1))
    lets say in A2 you have 1,20,10
    Red Part: Start of the mid
    add a comma before the text then substitutes all commas with a string of 100 spaces. Now think for 1 comma 100 spaces means length is 100+1(length of 1) for second comma again 100 spaces means length at this moment is 101+100+2 = 203 for third comma it becomes 203+100+2 = 305.

    Blue Part: starting number for mid
    100*(ROW(INDIRECT("1:"&LEN($A2)-LEN(SUBSTITUTE($A2,",",""))+1))) will become {100;200;300}

    last part of mid is 100 which is character to return.

    for first instance mid is asking start at 100 position and take 100 characters at this junction first character will be at 101st position and mid is looking for character between 100th - 200th position

    but for second instance mid is asking start at 200 position and take 100 characters at this junction first character will be at 203rd position and mid is looking for character between 200-300 position and so on for other instances

    with higher number in rept you can check for much big string with in MID.

    Trim then removes all excessive spaces and addition of 0 converts array of strings returned by MID to array Numbers
    =B$1 check if any number within array matches with the B$1 if yes then gives true's and If no then gives false

    -- mark converts trues to 1 and False's to 0 and then sumproduct sums all 1's and 0's.

    as sumproduct can handle array operations you don't need to confirm the formula with array confirmation
    Last edited by hemesh; 05-09-2014 at 07:50 AM.

+ 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. Help: take values from many columns into one list, separate list to new worksheets
    By celestealexandra in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-07-2013, 05:44 PM
  2. Splitting content in separate columns
    By jen2412 in forum Excel General
    Replies: 10
    Last Post: 08-28-2012, 06:19 PM
  3. Replies: 2
    Last Post: 06-28-2011, 10:29 AM
  4. splitting first, last, middle initial in separate columns
    By johnmerlino in forum Excel General
    Replies: 3
    Last Post: 10-21-2010, 09:25 AM
  5. Splitting Names into 2 separate columns
    By FreddyKruger in forum Excel General
    Replies: 11
    Last Post: 04-11-2008, 04:10 PM

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