+ Reply to Thread
Results 1 to 6 of 6

Macro to Calculate Date Difference

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-02-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    353

    Macro to Calculate Date Difference

    Hi everyone.
    Need to check with you guys as I'm really no good in VB Scripting or Macro.
    I have a situation in which i need to calculate the difference between two dates on two different columns.
    I know how to calculate the date difference using the formula
    =DATEDIF(F5,E5, "M")

    But what I need is to have this tiny button that I can click to return the difference between the two dates on a different column.
    By the way I need the difference in months.
    Please please please please please help me.
    Thank's all.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro to Calculate Date Difference

    Hello Andrew.Trevayne,

    Welcome to the Forum!

    The VBA code is almost the same as the worksheet formula. Your example would translate to this in VBA...
      Dim dd As Integer
    
        dd = DateDiff("m", Range("E5"), Range("F5"))
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    11-02-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    353

    Re: Macro to Calculate Date Difference

    Thanks for the welcome.
    Sadly I dont know how to use the formula you just gave, I really am NIL with regards to macro or Vb. I hope someone could further help?
    Thanks again. Cheers.

  4. #4
    Forum Contributor
    Join Date
    11-02-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    353

    Re: Macro to Calculate Date Difference

    I hope somebody would be able to help me on the macro codes on this one.
    I'm quite sure somebody knows how.. ^^

  5. #5
    Registered User
    Join Date
    06-11-2012
    Location
    Des Moines, Iowa
    MS-Off Ver
    2007/2010
    Posts
    1

    Re: Macro to Calculate Date Difference

    Hi Lieth, I used the same code and the code runs but the results dont show. Do you know how I can show the answers?

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to Calculate Date Difference

    Akdrake,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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