+ Reply to Thread
Results 1 to 30 of 30

splitting a long column of data into separate columns

  1. #1
    Registered User
    Join Date
    05-14-2008
    Posts
    56

    splitting a long column of data into separate columns

    Hello, i have a long column pair of data, each entry in its own cell:

    10/5/2008 8:30:00 AM
    10/5/2008 8:46:00 AM
    10/5/2008 9:14:00 AM
    10/5/2008 10:18:00 AM
    10/5/2008 10:42:00 AM
    11/5/2008 8:30:00 AM
    11/5/2008 8:46:00 AM
    11/5/2008 9:14:00 AM
    11/5/2008 10:18:00 AM
    11/5/2008 10:42:00 AM
    12/5/2008 8:30:00 AM
    12/5/2008 8:46:00 AM
    12/5/2008 9:14:00 AM
    12/5/2008 10:18:00 AM
    12/5/2008 10:42:00 AM
    13/5/2008 8:30:00 AM
    13/5/2008 8:46:00 AM
    13/5/2008 9:14:00 AM
    13/5/2008 10:18:00 AM
    13/5/2008 10:42:00 AM
    14/5/2008 8:30:00 AM
    14/5/2008 8:46:00 AM
    14/5/2008 9:14:00 AM
    14/5/2008 10:18:00 AM
    14/5/2008 10:42:00 AM

    how can i program a macro to 'split' this column according to date? please refer to the attached picture as an example. i know this is probably a simple question but please bear with me i'm still new to excel programming.

    thanks in advance!
    Attached Images Attached Images

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, Give this a try:-
    The resutant date formats are not quite correct may be my "country setting"
    Have a go, see what you find.
    Data in column "A". Results in column "B" on--.
    Please Login or Register  to view this content.
    Regards mick

  3. #3
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245
    Try this one. Be aware that everything is processed from bottom to top. Normally it would be start,stop time but in reverse it's stop, start.
    Please Login or Register  to view this content.
    Charlize

  4. #4
    Registered User
    Join Date
    05-14-2008
    Posts
    56

    charlize you never fail to amaze me

    thanks charlize and Mick G for your help, appreciate both answers, really. I tried both, and Mick G's code caused a Subscript Out Of Range error here

    Please Login or Register  to view this content.
    which i don't understand so i can't fix it on my own...

    charlize your code is simply amazing, you even added code to repeat the whole thing across every sheet. i tip my hat off to you, thanks so much.

    how do i exclude the first sheet from this macro? and is there a way to incorporate re-sorting the data into your code? perhaps a modification of:

    Please Login or Register  to view this content.
    Last edited by michaelkwc; 05-22-2008 at 05:13 AM.

  5. #5
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245
    After some revision of another idea, I came up with this one. I believe it's what you desire.
    Please Login or Register  to view this content.
    Charlize

  6. #6
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    Please Login or Register  to view this content.
    i'm getting this error: Application-defined or Object-defined error

    but it's been a long day and my head's melting, so perhaps it's an error on my side. will try again tomorrow, update how it goes.

    thanks again charlize, don't know what i'd do without you.

    ~Michael

  7. #7
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245
    Variation to split up the coding to locate the last row of the active column.
    Please Login or Register  to view this content.
    Charlize

    ps. - use F8 to watch the coding go and look at the values of the variables when they get changed. Just put your mouse above a word and you should see some yellow sticky notes that give some info about the value of a variable.
    - what's the value of vletter. The first time it should be C. Change the coding to determine the vletter to this
    Please Login or Register  to view this content.
    Notice the extra . before Cells. It seems that 2007 needs an explicit declaration of the range. In 2003 it works as showed.
    Last edited by Charlize; 05-22-2008 at 07:51 AM.

  8. #8
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    Please Login or Register  to view this content.
    by stepping into the code with F8, i discovered that the macro skips through this whole section of code; from
    Please Login or Register  to view this content.
    it just jumps to Else. thus vletter remains empty.

    I've enclosed a copy of the worksheet for you to have a look. had to zip it up cos excelforum doesn't allow *.xlsm uploads. the worksheet "Original" was split up using your split_data_employees macro, i've included split_data_of_day_V2 in the coding but it can't be run.

    again, thank you for your help, i don't know how i can repay you for the effort.
    Attached Files Attached Files
    Last edited by michaelkwc; 05-23-2008 at 12:59 AM.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    try
    Please Login or Register  to view this content.
    Last edited by jindon; 05-22-2008 at 11:56 PM.

  10. #10
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    thanks jindon, will try it out after i fix the formats.

    for some reason the cells are not formatted properly (my original data) so perhaps that's why all the coding's jumbled up. will update when i get it fixed.

    update: got the dates fixed, charlize's code still doesn't work, jindon's code doesn't split it but rather duplicates both columns of date&time over to columns C/D/E/F/G/H. i've uploaded an updated copy of the data file in post #8 of this thread.

    thanks for all the help, appreciate all of it.
    Last edited by michaelkwc; 05-23-2008 at 12:57 AM.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Quote Originally Posted by michaelkwc
    thanks jindon, will try it out after i fix the formats.

    for some reason the cells are not formatted properly (my original data) so perhaps that's why all the coding's jumbled up. will update when i get it fixed.
    Just to let you know.
    I wrote the code from your jpg screenshot as I can not open zipped file.

  12. #12
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    here's screenshots before and after. please pardon the poor quality of the "after" screenshot as it was exceeding the 100kb limit.
    Attached Images Attached Images

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Have you tried my code ?

  14. #14
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    yes, the screenshots were before and after using your code

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Done correctly ?

  16. #16
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    not really... this is what i want:
    Attached Images Attached Images

  17. #17
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245
    What's the value of lrow. Try changing it to this
    Please Login or Register  to view this content.
    and change the vletter thing to this
    Please Login or Register  to view this content.
    Charlize

    Ps.: Everything works just fine by me, even with the excel 2007 compatability thing.
    - Have you read my updated post, I guess not because your coding uses the old one.

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Just one set too many ?
    change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    after replacing lrow, and after stepping into F8, lrow=76

    when it reached
    Please Login or Register  to view this content.
    then it jumped to Else, thus skipping the vletter line altogether. then i get a application-defined or object-defined error at
    Please Login or Register  to view this content.
    2 lines after Else. At this stage, vletter="" and lrowvletter=1.

    Actually, if this gets too complicated or if it's taking too much of your time, i can work with your first code, and i added a line of code to skip the first sheet (see the [If Ws.Name <> "Original" Then] code at the middle):

    Please Login or Register  to view this content.
    this works perfectly well on my side only that it's reversed (OUT at the top, IN at the bottom, as you said). I tried to convert your Copy_Last_Cells macro to be compatible with this but lol trial and error does not always work in programming... this was your code:

    Please Login or Register  to view this content.
    and this is what i tried to convert it to, so as to process the data in the attached picture:

    Please Login or Register  to view this content.
    naturally i came up with tons of errors, so if you'd like, we can skip the whole V2 idea and work from the V1 idea, all i need is to modify your Copy_Last_Cells code to work by columns instead of rows. alternatively we can work with V2 since apparently it works fine on your side, so perhaps it's just a small tweak or two to get it working on mine.

    again, a heartfelt thank you.

    ~Michael
    Attached Images Attached Images
    Last edited by michaelkwc; 05-23-2008 at 03:19 AM.

  20. #20
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    @jindon

    not really, what your code does is just duplicate the original two columns, what i need is to *cut* the column by date (refer to correct.jpg at post #16)

    but thank you for replying, appreciate it too.

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Or I don't seem to understand your problem...

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Not sure if this is what you wanted...
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    basically, i want to convert before_test.jpg to correct.jpg.

    tested your code, it does nothing because

    Please Login or Register  to view this content.
    results in x=Error 2042, and thus at

    Please Login or Register  to view this content.
    it exits the program...
    Attached Images Attached Images

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    That is really odd,
    If the data in col.A are serial date, obviously they are, it should retrurn 7.
    try
    Please Login or Register  to view this content.
    P.S
    If still return error then try
    Please Login or Register  to view this content.
    Last edited by jindon; 05-23-2008 at 03:52 AM.

  25. #25
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245
    Yet another solution. What about this one.
    Please Login or Register  to view this content.
    Charlize

  26. #26
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    awesome. version 3 did the job perfectly. absolutely amazing.

    charlize, thank you.

    thanks also to jindon, your last code came close but somehow the dates got mixed up and stuff... included as an attachment if you'd like to see, as jindon_code_result.jpg. but it's okay now that the problem is solved, thanks also to you.
    _________________________________________________________________

    now just to tie up the loose string, regarding Copy_Last_Cells, how do i modify it to pick out the last pair of cells, then paste them out at row A61 onwards? i will add the code below to complete the IN-OUT pair at row A60:

    Please Login or Register  to view this content.
    Original copy_last_cells:

    Please Login or Register  to view this content.
    What i tried to do, but failed:

    Please Login or Register  to view this content.
    and the end result should be as in the attachment copy_last_cells_v2.jpg:
    Attached Images Attached Images
    Last edited by michaelkwc; 05-23-2008 at 05:38 AM.

  27. #27
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245
    Last revision with the in/out line. Change to 60 if you want it to appear at row 60. Used 20 for ease of view.
    Please Login or Register  to view this content.
    Charlize

  28. #28
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    i ask for a chicken bone you give me a drumstick...

    *big bow ala japanese-style*

    you are simply amazing, so kind and generous. thank you so much charlize for spending so much time and effort to help a noob like me with my problem. a personal vow - when i learn more about excel programming, i will return the favor to the community, like you did.

    thank you. there is no more i wish to ask.

    thank you.

  29. #29
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    I seem to understand what you are really after by your screen shots, however you seem to have solved the problem, so I will not post my solution.

  30. #30
    Registered User
    Join Date
    05-14-2008
    Posts
    56
    well since you've already done it why not post it? i'm trying my best to learn more coding so any example would be great. please post your code i would like to try and see what happens so i can learn from it.

+ 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