+ Reply to Thread
Results 1 to 19 of 19

split string in cell

  1. #1
    Registered User
    Join Date
    03-31-2014
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    48

    split string in cell

    Hi,
    do someone know a VBA code to split a string in cell with commas, e.g. text ABCD should be A,B,C,D?
    thanks a lot

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,297

    Re: split string in cell

    Something like this:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-31-2014
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: split string in cell

    thank you very much

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: split string in cell

    And if you have selected the cell - this also works

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,297

    Re: split string in cell

    @xladept: not sure there's much difference. Your solution will fail if an empty cell is selected. I know, because mine did and I fixed it.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: split string in cell

    NVM misread.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: split string in cell

    @ TMS,

    Good one Trevor!

    Only thing I would add is :

    Please Login or Register  to view this content.
    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: split string in cell

    Hi Trevor,

    I was hoping the OP would more definitively define(!) the object Cell.

    But you're right and I have "fixed" it

    Orrin

    Please Login or Register  to view this content.
    Last edited by xladept; 11-20-2018 at 03:54 PM.

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: split string in cell

    It just occurred to me that what if the Activecell contains a number off leading and/or trailing Spaces, which are not visible, and which none of the Code solutions addresses.

    I have taken the liberty to "Fix" TMS's Code to handle such cases, if any.

    Please Login or Register  to view this content.
    @ xladept,

    Maybe you could provide for same with your Code?

    Regards
    Last edited by Winon; 11-20-2018 at 04:39 PM.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: split string in cell

    @ Winon - I already did that

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,851

    Re: split string in cell

    An alternative solution if you have a very large data set would be to use Power Query.

    Here is the MCode
    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: split string in cell

    @ xladept,

    For some reason, if the cell contains only spaces, it bugs out on this line of your Code;

    Please Login or Register  to view this content.

  13. #13
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: split string in cell

    @ alansidman,

    You have totally lost me due to my ignorance of Power Query thus far.

    Could you please provide a sample Workbook of same for better understanding?

    Thank you.
    Last edited by Winon; 11-20-2018 at 04:53 PM. Reason: Spelling!

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,297

    Re: split string in cell

    @Winon: if the cell contains leading or trailing spaces, why would you assume they're not wanted?

    And you are testing and trimming the ActiveCell AFTER I set cell.

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: split string in cell

    For those "spacey cells":

    Please Login or Register  to view this content.

  16. #16
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: split string in cell

    @ TMS,

    Thank you for your response.

    I apologize if you feel that I should not have interfered with your Code, and I shall gladly remove it.

    Your original Code as offered in Post # 2 will then remain as is, and return the following sample Screenshot.


    Regards.
    Attached Files Attached Files

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,297

    Re: split string in cell

    @Winon: no apology necessary. More a comment than a criticism. Tinker with the code as you wish. With only one trivial example, who knows exactly what the OP is expecting?

  18. #18
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,851

    Re: split string in cell

    @Winon
    Attached file

    For anyone interested, there is a great book that makes this very simple to understand.
    M is for (Data) Monkey by Ken Puls and Miguel Escobar.
    Attached Files Attached Files

  19. #19
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: split string in cell

    @ alansidman,

    Thank you so much for your effort and time. I really appreciate it!

    Best regards.

+ 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] Split string when enter into certain cell
    By Allmaths in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-08-2015, 10:21 PM
  2. [SOLVED] Split String at every "/" then put split string results into a multiline textbox.
    By Andrew Andromeda in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2015, 01:49 AM
  3. [SOLVED] Split one string in cell after second semicolon
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-23-2014, 01:03 PM
  4. [SOLVED] Split Data in CELL numeric and String
    By allstarleb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-27-2012, 01:01 PM
  5. Can excels Split() function split a string up at multiple spots?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2011, 02:36 PM
  6. split string to another cell when find .dot
    By farrukh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-17-2011, 06:05 AM
  7. Split string in a cell
    By kaipan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-14-2009, 06:25 AM

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