Calculating the number of quarters between two given dates in different
years can be a challenge. Here is a UDF (user-defined function) you can
create with VBA to do the job.
Function QtrDiff#(dte1 As Date, dte2 As Date)
QtrDiff# = DateDiff("q", dte1, dte2)
End Function
Now enter the QtrDiff function in a cell, just as you would any
other formula. The only arguments will be addresses of the cells
containing the beginning date and the end date you want to use in the
calculation. For instance, if you have the date, September 1, 2001,
entered in range A1 and December 31, 2002 in range B1 --
in any other cell, enter this formula:
=QtrDiff(A1,B1)
Your custom function returns a value of 5, the number of quarters
between the two dates.
If you reverse the order of the dates, the function will return a -5,
a negative value indicating the date in the 2nd argument precedes
the 1st date.
Special thanks to Austen Marriott of e-Focus for helpful feedback to update this article.
Know an even better way?
Let me know.
|