+ Reply to Thread
Results 1 to 7 of 7

Help With Date Calculation Function

  1. #1
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Leeds, England
    MS-Off Ver
    MS Office 2007
    Posts
    134

    Help With Date Calculation Function

    Hi Everyone,

    I have been working on a function to calculate the number of months between two dates. I am now stuck as I am new to functions as well as VB2008.

    There is one value I want to input: dueDate
    There is one value I want to output at the end: debtMonths

    Can anyone see if I am going along the right lines and also how I can finish this off by using the function in a Macro.

    If I need to provide any more info please let me know.

    Thanks
    dvent

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    I assume you are not familiar with teh DateDiff VBA function (or the DATEDIF worksheet function for that matter)?

    Please Login or Register  to view this content.
    HTH

    Jason

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,202
    Place this code in a Standard Module

    Please Login or Register  to view this content.
    Place the Due Datew in A1 in B1 =calculateMonths(A1)
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Leeds, England
    MS-Off Ver
    MS Office 2007
    Posts
    134
    Thanks Roy,

    I have amended the function slightly as VB2008 came up with some errors (obviously I am not using Excel for this).

    Please Login or Register  to view this content.
    My final MsgBox gives the difference between EndDate and BeginDate like I need.

    Can anyone tell me now how I can use this function within my macro below:

    Please Login or Register  to view this content.
    What I am trying to say is if i declare an object of:

    Please Login or Register  to view this content.
    How do I assign the value of calculateMonths to this?

    Thanks again
    dvent

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,202
    You aren't using VBA?

    The messageboxes need deleting, I just put them in to check that I was getting the correct numbers.

  6. #6
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Leeds, England
    MS-Off Ver
    MS Office 2007
    Posts
    134
    I am using Microsoft Visual Basic 2008 Express Edition.

    Now that I have this function I want to be able to use it in a Macro/Class/???. I am not sure what it'll be called?

    It is a Windows Form I am producing. I am trying to assign the result from

    Please Login or Register  to view this content.
    to an object of CreditCard1Months. But I am stuck.

  7. #7
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Leeds, England
    MS-Off Ver
    MS Office 2007
    Posts
    134
    Ah I've cracked it:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Jump to todays date function.
    By Jazmania in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-01-2008, 04:10 AM
  2. Comparing one date to another
    By Rams in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2007, 10:02 AM
  3. function to sum based on date
    By Jondal in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-14-2007, 08:57 AM
  4. Date Function Inept
    By St0rmshadow in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-30-2007, 09:26 PM
  5. Using DATE function
    By extxbill in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-28-2006, 03:34 PM

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