+ Reply to Thread
Results 1 to 47 of 47

split one column data into different columns

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    split one column data into different columns

    Hello there

    I have some data that contains all the info in 1 column.
    I want a macro to split and distribute the data to different columns.

    I have attached the sample sheets.
    sample1 is the main sheet
    sample2 is the output sheet

    I want the data to look like in sample2.

    Please help

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    try
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jindon; 01-28-2013 at 07:02 AM. Reason: File attached

  3. #3
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Thanks Jindon
    It works like a magic.

    Is there a way to happen on the same sheet?

    Also is there a way the 'comments' column will stay in the same place, the remaining columns will start from column D.

    Thanks

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Looks ugly though...
    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Or do you mean like this?
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    after the split, the comments column stay in column A that replaces the original, and the remaining starts from column D.

    Can we do this????

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    See my last post.

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,463

    Re: split one column data into different columns

    I've only just spotted that you put this in the VBA forum - I've been working on a formula solution (attached).

    The formulae are all in Sheet2, copied down to row 10. If you want then on one sheet you can just cut and paste to Sheet1.

    Hope this helps.

    Pete
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Pete

    The formula works fine but I need the headings also to be taken from the column data without having me to be typed in.

    Jindon

    Your last post works as I wanted. Does this work for all the rows on the sheets till the 1st empty row??

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Should work unless you have blank row(s) within a data range.

  11. #11
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    ReDim b(1 To UBound(a, 1), 1 To 100)

    what does 100 signify here???

    and which line in the code states the data should start at column D?

    sorry I am trying to understand the code so that I can apply accordingly.

    is there a way to overcome if there are any blank rows within the data range??
    Last edited by kbaruin; 01-28-2013 at 07:54 AM.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Since you don't know the number of headings to be produced in the beginning, 100 is the number of column to be added tentatively.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    to give you more info, there are lot of other columns with data stays on this sheet. The column B will not contain blank cells which contains serials numbers
    column H contains the data to split. after splitting the column H is replaced with only the comments, the remaining data is copied to column R-column Y.

    Hope this helps

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Then you should have uploaded the file with the similar layouts.

    Guess work always takes too much time.

  15. #15
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    sorry attached the actual datasheet.

    Please advice

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Need to see your desired result.

  17. #17
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Atached the desired result sheet

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    The rows are merged in the raw data as well as your desired result.

    Is that how you wanted?
    If so, what is the reason?

  19. #19
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Hi

    the file was in a different format sorry. FInd attached the copies of the raw data and the desired data sheets.
    sorry for back and forth msgs.

    THanks
    Attached Files Attached Files

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Now you are asking completely different problem.

    It can not be done without knowing all header details beforehand.

    such as

    Overhaul base
    Removal Detail
    Removal ATA
    etc.

  21. #21
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: split one column data into different columns

    @ jindon
    I was playing with this on the original files from Post #1
    It might be faster to split the data this way, rather than using Redim(), it can be expensive in larger sheets.

    Also, see how I decided what the headers are.

    The code isn't perfect by any means, but it might give you some more ideas.

    I lose all interest when the OP says that the data provided is nothing like the real thing. ...

    Please Login or Register  to view this content.
    Last edited by Marcol; 01-28-2013 at 09:48 AM. Reason: trying to correct mystery typos, but can't!
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  22. #22
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    The headers will always be the ones as stated below from column R to Y. But these wont appear initially before we run the macro.

    Overhaul base Removal Detail Removal ATA Module HSR Module CSR TGT MW N3 MW PELM Score


    sorry for all the confusing msgs.

    can this be done???

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Is there possiblity to have the data like

    Overhaul base:abc xyz Removal Detail: def

    means item has more than one word.

  24. #24
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    yes there might be more than one word for each item and its not necessarily be all the items will have data.

    for eg:

    RCI 1-3948021 Overhaul base: xyz Removal Detail:abc def Removal ATA:abcds Module HSR:sda Module CSR: TGT MW: N3 MW:dsds PELM Score:1.0
    Last edited by kbaruin; 01-28-2013 at 10:32 AM.

  25. #25
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Then can you upload a sample with the possible pattern of the data as similar as possible to your real data.

    Most of the item after column(":") has no space, however you have a space after Removal Detail:.

    See H3.

    Is that also happen?

  26. #26
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    This will only work if the items are

    All small letters and/or numbers.

    Please Login or Register  to view this content.

  27. #27
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Attached the sample data and desired data.
    Attached Files Attached Files

  28. #28
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    You should always remember when you ask questions such like this, data and layouts should be similar to your actual, otherwise it will be just wasting time for both of us.
    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Hi Jindon

    Thanks for the help and the code works fine. Can we include the formatting(font,size etc) also for the new columns added to appear as the rest please??

    Thanks

  30. #30
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.

  31. #31
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Jindon

    For some reason your code doesn't work on this file. see attached.

    I have downloaded the same data in csv format and tried running the code but no effect. can you check this please?
    also can we leave the comments column as is and just copy the data into different columns instead of cut and paste.

    The comments column will have '[LCM]' tag before the data in each cell. // if this info helps

    Thanks

  32. #32
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Add 2 lines
    Please Login or Register  to view this content.

  33. #33
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    can we leave the comments column as is without trimming the data and just copy the data to the new columns please.
    also when I run the macro, the headings row is missing the borders. Can you check this as well.

    THanks for your everlasting support and help

  34. #34
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Can you show me how exactly you want for the result?

  35. #35
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    see attacahed

  36. #36
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    It seems exactly the same as one before.

  37. #37
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    No, if you do the wrap text on the sheet, you can see the column H will have all the data after copying the data to the new columns from R to Y.

  38. #38
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Is this the result that you want? No separation? No formatting? etc.etc.

  39. #39
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    I need the formatting, I donno what you mean by seperation but I need the comments box to stay as it is without having to trim the details. Just copy the data to respective new columns.

  40. #40
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    I think I've lost.

    You just wait and see if someone else to come in and help you.

  41. #41
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Jindon please dont leave this task at its final stage.
    I am struggling to explain you the desired result..........leave the formatting issue
    can you help with just copying the data to the new columns leaving the comments column as is....

    Thanks

  42. #42
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    What I don't like is the thread asking one by one.

    I just need what you have and what you exactly want.

    Show me what you exactly want as for the result including cell format/borders/cell color etc.

  43. #43
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Please Login or Register  to view this content.
    added few things in the code as to get a desired result. I have copied the values to array b so that the split and replace operations will not disturb the values in array a as I wanted the column 8 to stay the same.

    but am unable to as the \n charector on column 8 is being replaced with spaces I guess and I am struggling to uderstand what this 2 lines does:
    Please Login or Register  to view this content.
    can you add the comments for me to understand.

    Thanks

  44. #44
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Only my guess.
    If this is not what you wanted, again need to see exact before/after thing.
    Please Login or Register  to view this content.

  45. #45
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Not as I wanted. PLease see attached raw and desired results.
    Thanks again
    Attached Files Attached Files

  46. #46
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: split one column data into different columns

    Delete 2 lines in red
    Please Login or Register  to view this content.

  47. #47
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: split one column data into different columns

    Thanks very much Jindon.

    You are a Star

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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