+ Reply to Thread
Results 1 to 12 of 12

Splitting column into multiple columns (of varying size)

  1. #1
    Registered User
    Join Date
    02-19-2019
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    MS Office 2010
    Posts
    24

    Splitting column into multiple columns (of varying size)

    Hi all,

    I would like to request your help.

    I have build a vba code which provides me with a column full of data. The length of this column is a variable, different each time.

    In this column, each cell contains either one or multiple names, divided by a comma

    Thus, say starting Column "K4:K8" (but length is variable)

    AA,BB,CC
    AA,CC,
    BB
    AA,BB,DD
    AA

    Out of all this information, I would like to list the different names, and paste them somewhere else.

    Thus:

    AA
    BB
    CC
    DD

    I tried splitting the cells, but due to the varying nature, I was not able to make it work.

    So my plan was: after splitting, I would have to remove the commas, put all data in a single column and remove duplicates and sort it alphabetically.

    Any help would be much appreciated.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Splitting column into multiple columns (of varying size)

    Hi & welcome to the board
    How about
    Please Login or Register  to view this content.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,368

    Re: Splitting column into multiple columns (of varying size)

    Hi,

    This is a much easier problem using the Power Query Tool that you can install as an Add-In to 2010 Excel.

    https://www.microsoft.com/en-us/down...3-c473f96bc2de

    Using PQ you select a cell in the range and Edit the range in the PQ tool/view. You would do the steps you suggested in your question without needing to write any code. The PQ steps look like the below.

    Please Login or Register  to view this content.
    PQ Split Remove Dups Sort.xlsx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    02-19-2019
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    MS Office 2010
    Posts
    24

    Re: Splitting column into multiple columns (of varying size)

    Hi Fluff13,

    Thank you for your warm welcome and the help. I will try to implement your formula into my workbook.

    If you don't mind me asking, I am new to "CreateObject("scripting.dictionary")".. I just googled it and it seems it acts as some kind of variable in which you can save multiple items?

    Edit: I just tried to implement it and it did not completely do the job:

    Split Names.PNG

    I believe it has to do with moving the L4 part?

    Thanks,

  5. #5
    Registered User
    Join Date
    02-19-2019
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    MS Office 2010
    Posts
    24

    Re: Splitting column into multiple columns (of varying size)

    Hi MarvinP,

    Thank you for your help.

    However, I am more or less unable to install add-ins and therefore have to stick to (pure) VBA.

    I most certainly appreciate your help, but have to look for an VBA solution to the problem..

    Kind regards,

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Splitting column into multiple columns (of varying size)

    In what way didn't it work?
    From what you have posted, that's what I'd expect in that col L has all the unique values from col K.
    For more about dictionaries have a look here https://excelmacromastery.com/vba-dictionary/

  7. #7
    Registered User
    Join Date
    02-19-2019
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    MS Office 2010
    Posts
    24

    Re: Splitting column into multiple columns (of varying size)

    Hi FLuff13,

    I do apologies. I had the impression it had split just K4 into L4:L6, but it had actually done all steps in one sweep..

    That is actually amazing, "Dictionary" is a very powerful tool.

    You (via "Dictionary") skipped splitting the value in multiple columns, putting them together below each other, removing commas etc..

    Thank you very much, I will try to fully understand the function!

    Kind regards

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Splitting column into multiple columns (of varying size)

    You're welcome & thanks for the feedback

  9. #9
    Registered User
    Join Date
    02-19-2019
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    MS Office 2010
    Posts
    24

    Re: Splitting column into multiple columns (of varying size)

    Hi Fluff13,

    I would like to run through one more thing with you on this:

    If I would have cells with a space after the comma, it would give both the name with and without a space before it:

    AA, BB, CC
    AA
    AA, CC
    CC
    AA, BB
    BB

    For example would give me:

    AA
    BB
    CC
    CC
    BB

    Which makes for an interesting case. As I am only looking for the ones without a space in front of it. I thought about removing the Spaces in the whole column first, but that would turn all double names into a single string: John Doe would become JohnDoe, which is not ideal.

    I could manipulate the input by removing all spaces after the comma? Thus add something like replace(c1, ", " , ",") within the sub?

    Looking forward to your view.

    Best,

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Splitting column into multiple columns (of varying size)

    If you make this change
    Please Login or Register  to view this content.
    It will cater for commas with & without a space afterwards

  11. #11
    Registered User
    Join Date
    02-19-2019
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    MS Office 2010
    Posts
    24

    Re: Splitting column into multiple columns (of varying size)

    The trim addition indeed solved the problem!

    This forum is very useful for efficient coding, as the "simple" trim is more efficient than rewriting columns etc..

    Once again, much appreciated! I added reputation to your post

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Splitting column into multiple columns (of varying size)

    Glad to help & thanks for the feedback

+ 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. Transpose Multiple (& Varying) Rows into Multiple (& Varying) Columns
    By Andrea9578 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2017, 11:46 AM
  2. Transpose Multiple (& Varying) Rows into Multiple (& Varying) Columns
    By Andrea9578 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2017, 02:05 AM
  3. [SOLVED] Build Column D based on Columns A, B, and C (which have varying size and content)
    By amanzi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-18-2016, 11:43 AM
  4. Replies: 3
    Last Post: 03-27-2013, 03:58 PM
  5. Replies: 2
    Last Post: 07-09-2012, 01:44 PM
  6. Splitting a column in CSV to multiple columns
    By Nehalem in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2012, 07:08 AM
  7. Splitting one column into multiple columns
    By paintermonkey@gmail.com in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-02-2006, 03: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