+ Reply to Thread
Results 1 to 20 of 20

Changing time format without losing data

  1. #1
    Registered User
    Join Date
    11-21-2006
    Posts
    9

    Changing time format without losing data

    I have a worksheet that has data in the format of
    1/1/06 1330. Representing the date and time
    I need the data to be formatted as
    1/1/6 13:30
    so that I can use functions to calculate the difference between cells in time.

    I tried using the formulate cells command and it replaces all of the data with zeros, but in the correct format.

    Any help is appreciated. A macro, a copy and paste work around a formula??

    Thanks, lj

  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    I am assuming all your data is formatted as Text ... right ?

    Carim

  3. #3
    Forum Contributor
    Join Date
    10-27-2006
    Location
    United Kingdom
    MS-Off Ver
    EXCEL 2003 (2007 at home)
    Posts
    517

    Try This

    Assuming your value is in A2, then in B2 (for example) enter:

    =DATEVALUE(LEFT(A2,FIND(" ",TRIM(A2))))+TIMEVALUE(LEFT(RIGHT(A2,4),2)&":"&RIGHT(A2,2))

    Select the custom format dd/mm/yy hh:mm (or mm/dd/yy hh:mm if not UK)

    Note that this might fall over if the input format changes too much...

    Mark.

  4. #4
    Registered User
    Join Date
    11-21-2006
    Posts
    9
    I believe my cells are formatted as text. How can I check this?

    I tried the formula above and it did not work. All of my date/time data is in one cell, so I'm not sure if that would make a difference.

    lj

  5. #5
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Well it makes a big difference ...
    all the data is in one text cell and as Scott pointed out with a variable structure ...

    Could you upload a zipped version of your file ?

    HTH
    Carim

  6. #6
    Registered User
    Join Date
    11-21-2006
    Posts
    9
    I can't upload zip files, I don't have that ability on this computer.

    I could just cut it to a few lines of data and upload it that way?

    Where would I upload it?

    lj

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Uploaded it to

    http://www.savefile.com/

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  8. #8
    Registered User
    Join Date
    11-21-2006
    Posts
    9
    Okay, the file has been uploaded to
    Savefile.com

    The data I am looking at is in column B and D.

    Some of the data looks properlly formatted. I used the find and replace for these.

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    You need to post the link it gives you for file

    VBA Noob

  10. #10
    Registered User
    Join Date
    11-21-2006
    Posts
    9
    That is a direct link to the file, I just called it Savefiles.com

    Here it is again.
    www.savefiles.com/files/279197

  11. #11
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Not working mate

    Try http://cjoint.com/

    VBA Noob

  12. #12
    Registered User
    Join Date
    11-21-2006
    Posts
    9

  13. #13
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    The link should of being

    http://www.cjoint.com/data/lvvI4kDwr6.htm

    Column B and D ar both formatted as Date and Time. There is no times as far as I can see formatted as 1300 instead of 13:00

    The below will change 11/15/06 4:30 into 11/15/06 04:30 for you

    =DATE(YEAR(B2),MONTH(B2),DAY(B2))+TIME(HOUR(B2),MINUTE(B2),SECOND(B2))

    If you want the date and time in Col G and H use

    =DATE(YEAR(B2),MONTH(B2),DAY(B2))

    and

    =TIME(HOUR(B2),MINUTE(B2),SECOND(B2))

    VBA Noob

  14. #14
    Registered User
    Join Date
    11-21-2006
    Posts
    9
    This only worked for cells where I had used the find and replace to add the ":"

    Look at line 45 to see the way the data was originally entered.

    Thanks
    lj

  15. #15
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Try this in G2 and drag down. Then select column and paste special as values and format as required

    =IF(ISERROR(DATE(YEAR(B2),MONTH(B2),DAY(B2))+TIME(HOUR(B2),MINUTE(B2),SECOND(B2))),LEFT(B2,FIND(" ",B2))&SUBSTITUTE(RIGHT(B2,4),RIGHT(B2,2),":"&RIGHT(B2,LEN(B2)-FIND(" ",B2)-2)),(DATE(YEAR(B2),MONTH(B2),DAY(B2))+TIME(HOUR(B2),MINUTE(B2),SECOND(B2))))
    VBA Noob

  16. #16
    Registered User
    Join Date
    11-21-2006
    Posts
    9
    Were you able to get this to work?

    I tried and have been unsuccessful. I pasted the formula into G2 then copied it and "drug down". Then I copied column G and pasted special into column H. I had already used the Format cells command for column H to get the date format that I want.

    I even tried formatting the cells after I entered the data with no luck.

    Thanks, lj

  17. #17
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    There is absolutely no consistency in your data ...
    Try to normalize it beforehand ...

    HTH
    Carim

  18. #18
    Registered User
    Join Date
    11-21-2006
    Posts
    9
    Would it be easier if I separated the data and had date and time in different columns. Then once I had it formatted correctly, merge the columns into one?

    The lack of consistency is from trying so many different ways to format these cells. I hate to revert back to the original document and lose all of the cells that are formatted correctly, because those I used find and replace (time consuming). This data is also coming from a report writing program and being brought into Excel, so I have limited ability on how to format before the data is entered.

    If you can help me with this I would gladly run the report and reimport it into Excel, if it would help.
    Last edited by lajones3; 11-21-2006 at 05:42 PM.

  19. #19
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Yes,

    See attached

    VBA Noob
    Attached Files Attached Files

  20. #20
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi again,

    The only thing I can provide you with is a starting point with all the formulas,
    based on your initial input ...

    HTH
    Carim
    Attached Files Attached Files

+ 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