+ Reply to Thread
Results 1 to 5 of 5

Date difference

  1. #1
    Registered User
    Join Date
    10-25-2011
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    23

    Date difference

    Hi again

    Ive been trying to subtract two dates- ie today - copy/paste dates in excel spreadsheet

    I get an error in vba and a !value! in excel. I think it has to do with the formatting as it works with dates that dont have the 13 and up in them, but answer is wrong. Ive tried formating the cells from menu and no luck. How can I get it to take the difference?
    Thank you again
    Mike

    Here is a sample of dates:
    12/13/11 09:30
    12/13/11 20:19
    12/15/11 10:10
    12/20/11 15:44
    12/23/11 08:30
    01/03/2012 14:05
    01/04/2012 18:15
    01/09/2012 12:16
    01/09/2012 12:16
    01/09/2012 12:21

    code does not work

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Date difference

    Works fine for me, a;though it does format it as a date.

  3. #3
    Registered User
    Join Date
    10-25-2011
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Date difference

    Hi Bob

    Thats interesting! I cant seem to get it to work. I just tried a new workbook and did another paste and it does not work for this date:
    08/29/11 11:31
    vba gives type mismatch error

    It will work for
    01/12/2011 9:55
    12/12/2011 16:03

    Note that the column with dates, some are left justified (dont work, digits greater than 12) and right justified (works, digits less than 13)
    Would there be another way of doing this difference?

    Thanks
    Mike

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Date difference

    The code you gave doesn't use any dates on the workbook, so I cannot see the problem.

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Date difference

    Normally dates are right justified. If some columns are left justified chech is it date or string.
    pl also check:date1 ,date2 are to declared as dates and ans to be integer.
    Other than this no problem observed as already told by others.

+ 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