+ Reply to Thread
Results 1 to 14 of 14

Need macro to split one column into multiple columns based on _ and spacing

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    18

    Exclamation Need macro to split one column into multiple columns based on _ and spacing

    1010_BIERMAN_5530_07092012.pdf 8/31/2012 6:00:22 PM
    10469_EVANS_5530_07112012.pdf 8/31/2012 6:00:22 PM
    1048_CASTIGLIONE_5510_08212012.pdf 8/31/2012 6:00:22 PM
    10499_LAUDERDALE_5520_07052012.pdf 8/31/2012 6:00:22 PM

    Okay folks. I Need each of the examples split up (in a macro) to seperate everything before/after a _ to a seperate column.
    There are three exceptions
    1)***HOWEVER, the .pdf can get taken out of the end***
    2)***I need to convert the last numbers (before the .pdf) into date format (MM/DD/YYYY) (I.e 07052012 would be 7/5/2012)
    3)***If the cell contains something like 8/31/2012 6:00:22 PM (after a bunch of the spaces) then please insert This Date(+TIME) into ANOTHER column. I am not certain each pdf name will have a separate date attached, but for this example, they are***

    In Total, 5 columns (correct me if I am wrong)

    This would be a huge life saver. Thanks so much guys!

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Need macro to split one column into multiple columns based on _ and spacing

    It would be better if you upload a real data example with all possible scenario in one sheet and on another sheet show the output.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    06-04-2010
    Location
    Baku
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Hi, it seems you need text to columns for separation. (use "_" seperator as you stressed above). Data/data tools/text to columns

  4. #4
    Registered User
    Join Date
    08-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Quote Originally Posted by mike7952 View Post
    It would be better if you upload a real data example with all possible scenario in one sheet and on another sheet show the output.

    test.xlsx

    Please reference sheet 'From JT' which would show examples of what I am looking for.

    Any help with automating this as fast as possible would be great

    Thanks

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Need macro to split one column into multiple columns based on _ and spacing

    This will work on the from jt worksheet.

    Please Login or Register  to view this content.
    will need to adjust 3 to your starting row.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-04-2010
    Location
    Baku
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Quote Originally Posted by mike7952 View Post
    This will work on the from jt worksheet.

    Please Login or Register  to view this content.
    will need to adjust 3 to your starting row.
    Please Login or Register  to view this content.
    It is not working. It is returning 07092012 when I need that to auto-convert that column to 7/09/2012. I cannot do it manually. Then there is a column to the right of that that is returning only 0. That I am not so worried about.

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Need macro to split one column into multiple columns based on _ and spacing

    I will see what I can do, I went off the data in Column I in your required output sheet(from jt), and it shows 5072012 not 5/07/2012

  9. #9
    Registered User
    Join Date
    08-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Perfect Mike. However, Column I may not always be there. There are situations where we need two dates. The number in column H should be converted to dd/mm/yyyy, that is more along the lines of what I was looking for.

    IFF there is a 69725_MORTIMER_5530_07132012.pdf 9/4/2012 4:00:23 PM then I would need column I

    Otherwise

    I would need exactly what you gave me but instead of '7132012' in column H I would want 7/13/2012 done automatically for me.

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Need macro to split one column into multiple columns based on _ and spacing

    this will work if there are 8 digits. Example of a problem from you test data is 72221_LIGHTBODY_5530_052920122.pdf. row 354

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Can you make it work universally? Regardless of the amount of characters?

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Probably can, but Im positive it would be near impossible to code for every possible amount of characters.
    Example LIGHTBODY_5530_052920122.pdf is one issuse that we are aware of. In this we know to drop the last 2 and we would get 5/29/2012. What if it was named LIGHTBODY_5530_052922012.pdf and the extra 2 is after the 9.


    I removed b(i, 4) = CDate(s(3)) so the code should run without error, but the date format will not be correct if there are not 8 digits or the digits are not of a real date.

    Please Login or Register  to view this content.

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

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Different method for Sheet1

    Perhaps few lines are not converted properly though...
    Please Login or Register  to view this content.
    Last edited by jindon; 09-13-2012 at 10:24 PM.

  14. #14
    Registered User
    Join Date
    08-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Need macro to split one column into multiple columns based on _ and spacing

    Thank you for including this different method - It has exactly what I need. I appreciate everybody's help in resolving this matter - now task #2 will be posted shortly!

    Need the best of the best for this one

    Regards

    Dan

+ 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