Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2008
    Location
    NM, USA
    Posts
    97

    Question Unanswered: A Simple question.

    Okay, be gentle. I am not a noob to VBA, but I AM a noob to using it with MS Excel.

    There doesn't seem to be a built in function that can take two dates and tell me "there's x many years between them", so I was trying to do it in VBA. After just a few minutes I felt like I had just sunk from pro to drooling moron, because I realize I have no idea what I'm doing.

    I know how to write a function, but...how um... How do I USE it?? How do I get the function I wrote from the VBA module into that cell that needs to do the calculatin'?
    "Unix is user friendly... It's just very picky about its friends."

    The best things in life...are well-documented.

  2. #2
    Join Date
    Sep 2008
    Location
    NM, USA
    Posts
    97
    Nevermind, I figured it out.
    "Unix is user friendly... It's just very picky about its friends."

    The best things in life...are well-documented.

  3. #3
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    511
    Hi,

    There are several ways to do it with native Excel worksheet functions.

    For reference, there's a not very well known Excel worksheet function called DATEDIF(), which is not to be confused with the VBA function called DATEDIFF(). I believe only Excel 2000 helpfiles contain any information on it, which is why most users aren't familiar with it. To get x number of years between two dates you can use it like this:

    =DATEDIF(A1,A2,"y")

    where A1 contains the earlier date and A2 contains the later date.

    For more information about the DATEDIF() worksheet function, have a look at Microsoft Excel MVP Chip Pearson's excellent article:
    http://www.cpearson.com/excel/datedif.aspx


    Hope that helps...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •