+ Reply to Thread
Results 1 to 11 of 11

Calculate the number of Months between two Dates (DATEDIF M)

  1. #1
    Registered User
    Join Date
    06-27-2019
    Location
    Rhode Island
    MS-Off Ver
    2016
    Posts
    13

    Post Calculate the number of Months between two Dates (DATEDIF M)

    Greetings,

    I am trying to calculate the number of months between two cells within my spreadsheet using VBA but I am having issues...

    What I would like to do is find the Date1 and Date2 in their respective columns cells and out the months to the respective column cell.

    Column AN (Starting in Cell 7) = Date1
    Column AP (Starting in Cell 7 ) = Date2
    Column AO (Starting in Cell 7 ) = Months between Date1 and Date2

    I can use this code in each cell to do it but I want to be able to do this with VBA
    Please Login or Register  to view this content.

    What I tried and I know its wrong but thought I would post it.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Last edited by nigelog; 10-17-2019 at 12:25 PM.

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    See next UDF

    AO7 =DateDiffPerso(AN7,AP7)
    Copy and paste down as needed
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  4. #4
    Registered User
    Join Date
    06-27-2019
    Location
    Rhode Island
    MS-Off Ver
    2016
    Posts
    13

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    Awesome, I used the Test2 and it worked great. One further question, is there a switch I can use to run Test2 when ever something is entered in Column AN and AP?

    Quote Originally Posted by nigelog View Post
    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    Maybe
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-27-2019
    Location
    Rhode Island
    MS-Off Ver
    2016
    Posts
    13

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    Hi and thank you,

    I want to be sure that this only runs on two of my worksheets. The Month and Report worksheets. Not all of the other 9 or so worksheets in my workbook.

    Quote Originally Posted by nigelog View Post
    Maybe
    Please Login or Register  to view this content.

  7. #7
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    Place in the worksheet module of the sheets you want - by right click sheet tab - view code

  8. #8
    Registered User
    Join Date
    06-27-2019
    Location
    Rhode Island
    MS-Off Ver
    2016
    Posts
    13

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    Hi, when I do that I get a Debug error from another script I am running across the workbook.

    It breaks the below: At Worksheets(WSname)

    Please Login or Register  to view this content.

  9. #9
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    Your Sub name suggest making the array sheets visible so would not

    Please Login or Register  to view this content.
    be correct

    Please Login or Register  to view this content.
    appears to be hiding?

    And code in a worksheet module should not affect this code which I assume is in a module

  10. #10
    Registered User
    Join Date
    06-27-2019
    Location
    Rhode Island
    MS-Off Ver
    2016
    Posts
    13

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    I had some other junk code on the other Worksheets VBA area. I removed it and it works great thank you for all your help!

  11. #11
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Calculate the number of Months between two Dates (DATEDIF M)

    No problem .. glad to have helped

    Thankyou for the feedback and rep

+ 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. [SOLVED] Formula to calculate the number of months between two dates
    By mysticmoron109 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 08-31-2015, 10:08 AM
  2. [SOLVED] Trying to calculate the number of months AND weeks between two dates..
    By DigitalWavez in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-01-2014, 04:43 PM
  3. Replies: 8
    Last Post: 02-20-2014, 05:46 PM
  4. Calculate number of months between dates
    By steph44haf in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-17-2013, 08:31 PM
  5. Calculate the number of Months between dates
    By Johndrew in forum Excel General
    Replies: 2
    Last Post: 09-03-2010, 02:18 AM
  6. Calculate number of months between 2 dates
    By john liem in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 06-01-2005, 10:05 AM
  7. [SOLVED] Calculate number of months between 2 dates
    By john liem in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 06-01-2005, 06:05 AM

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