Solved

VBA Excel Date Calculation

Posted on 2010-11-25
11
471 Views
Last Modified: 2012-05-10
Hi,

I am looking for a way to give me the total number of months between 2 dates, for eg. "2012/03/30 - 2010/09/30"

Please can someone give me the formula that will produce the result of : 18
0
Comment
Question by:NerishaB
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 1

Accepted Solution

by:
NeilJamesCotton earned 167 total points
ID: 34212382
There is a function called DateDif

=DATEDIF(A1,B1,"m")

Where A1 and B1 contain the two dates that you want to compare.

Hope this helps.
0
 
LVL 8

Assisted Solution

by:ragnarok89
ragnarok89 earned 167 total points
ID: 34212384
If the earlier date is in cell A1 and the later date is in cell A2 :-
=DATEDIF(A1,A2,"m")
This will give the rounded down difference in months.

Al
0
 
LVL 11

Assisted Solution

by:Runrigger
Runrigger earned 166 total points
ID: 34212385
datediff("m",datefrom,dateto)
0
 
LVL 11

Expert Comment

by:Runrigger
ID: 34212388
Authors request is for VBA version, correct?
0
 
LVL 1

Expert Comment

by:NeilJamesCotton
ID: 34212400
Sorry, you also need to make sure that the Cells that contain dates are formatted as DataType "DATE"

Highlight the cells in question, right click and choose "Format Cells", from the category list, select DATE and also select the display formatting that you want to format the date in. (The type of display formatting shouldn't effect the formulae) as long as you select an option from the DATE category.

Hope this helps
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:Runrigger
ID: 34212401
Which version of Excel does the DATEDIF function come in at, my company uses Excel 2007 and it does not exist!
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34212418
DATEDIF is in Excel 2007, just not in the help.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34212428
Or in the function dropdown, I just noticed.
0
 
LVL 11

Expert Comment

by:Runrigger
ID: 34212450
How bizarre not to have help and/or intellisense for it, do you know the reason, I have written my own UDF because I didn't know it existed!

Is there a master list of "hidden" functions out there Rory?
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34212492
That's the only one I know of. I don't think anyone outside MS knows why - see Chip's discussion here: http://www.cpearson.com/Excel/datedif.aspx
0
 

Author Closing Comment

by:NerishaB
ID: 34212523
Thanks guys
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Configure Sharepoint 2013 to allow Excel files to be edited online 9 57
Delete texts with font color 16 30
splitting text of cell to columns 14 24
Help with Excel formula 6 38
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now