+ Reply to Thread
Results 1 to 16 of 16

Split Names using macro

  1. #1
    Forum Contributor
    Join Date
    11-18-2007
    Posts
    111

    Split Names using macro

    Hello Every One,
    I need big help here..
    I have file that may contain about 100 or more rows depending on the request. In column A, i have several names that is seperated by comma in ever row so basically what i want to do is to remove each name and insert a new column and paste the removed name in the new column and keep doing that until only one name is left for each row. I would like the code to check every row until the last row of the file and perform the splitting method that i have mentioned above. Pls. note that some row may contain only one name in this case we don't need to copy and insert new column but if the row contains more that one name then i would like to split it as shown below. I have attached file for details. I really appreciate for your help.

    Here is an example of the current issue
    Mike, David, John
    Eric, Dave
    Joe, Johnson, Edward, Ellen
    Thompson, Adrienne

    Here is the desired output i would like to see:
    Mike
    David
    John
    Eric
    Dave
    Joe
    Johnson
    Edward
    Ellen
    Thompson
    Adrienne


    Thank you .... Thank you so much

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    This may do what you wish.
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    11-18-2007
    Posts
    111
    shg,
    I have tried to use the code but it is not working at all and i am not sure what is wrong with it. Could you please take a look and let me know. Thanks for your time and help.

  4. #4
    Forum Contributor
    Join Date
    08-28-2006
    Posts
    280
    I'm not shg. but go to the module where you installed the macro and delete the 57 out of the title Sub k57() so that it reads Sub k() and it should work for you. Otherwise it will keep jumping to cell k57 on the sheet.

    Dean

  5. #5
    Registered User
    Join Date
    10-04-2007
    Posts
    32
    The code works fine for me. Are you sure your putting it in the proper sheet you need the names separated in?

  6. #6
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    With the names in A1 to A4 shg's macro works for me. replacing the names in A1 to A4 with a single name in A1 to A11
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  7. #7
    Forum Contributor
    Join Date
    11-18-2007
    Posts
    111
    I removed the "57" and it took care one problem but i am still getting an error that reads like "Type mismatch"
    I am sure it is not working for me. Pls. help. Thanks for your time and help.

  8. #8
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    What line of code is highlighted at the time the error message is generated?
    What version of Excel are you using?

  9. #9
    Forum Contributor
    Join Date
    11-18-2007
    Posts
    111
    The code stops at line 13. I am using Excel 2002. Thank you so much for your effort

  10. #10
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try this Version (1 command changed)

    Please Login or Register  to view this content.
    I assume by line 13 you are refering to
    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,648
    Quote Originally Posted by karinos57
    Hello Every One,

    Here is an example of the current issue
    Mike, David, John
    Eric, Dave
    Joe, Johnson, Edward, Ellen
    Thompson, Adrienne

    Here is the desired output i would like to see:
    Mike
    David
    John
    Eric
    Dave
    Joe
    Johnson
    Edward
    Ellen
    Thompson
    Adrienne


    Thank you .... Thank you so much
    try
    Please Login or Register  to view this content.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Quote Originally Posted by Dean
    delete the 57 out of the title Sub k57() so that it reads Sub k() and it should work for you. Otherwise it will keep jumping to cell k57 on the sheet.
    What makes you think that, Dean?
    Quote Originally Posted by mudraker
    Please Login or Register  to view this content.
    No harm, no foul, but Split always returns a zero-based array (i.e., irrespective of Option Base).

    If anyone's suggested changes work for you, great. If not, please post a sample workbook that illustrates the problem, and I or someone else will help get it sorted out.

  13. #13
    Forum Contributor
    Join Date
    11-18-2007
    Posts
    111
    Guys, I would like first to thank you for your effort helping me out but for some reason the code fails at:
    For Each e In a
    or
    For Each v In x

    It seems that it does not pass at this line for some reason. I think it has to do with the version of Excel i am using which is 2002 and i could be wrong too.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,648
    Quote Originally Posted by karinos57
    Guys, I would like first to thank you for your effort helping me out but for some reason the code fails at:
    For Each e In a
    or
    For Each v In x

    It seems that it does not pass at this line for some reason. I think it has to do with the version of Excel i am using which is 2002 and i could be wrong too.
    Thers shoud be no problem with 2002, unless you have blanks within the range.

    Explain the details of the data range.

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello karinos57,

    You can use a For...Next to replace the For...Each. I made the changes below...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,648
    Quote Originally Posted by Leith Ross
    Hello karinos57,

    You can use a For...Next to replace the For...Each. I made the changes below...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    1) You can't split the counter
    2) You are using "v" as a counter

    What is this code for?

+ 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