Excel: Average Number of Years, Months, and Days Between DatesLast reviewed: June 27, 1997Article ID: Q51309 |
SUMMARYThe following Microsoft Excel function macro calculates the average number of years, months, and days between a list of start and end dates. To use this macro, enter the following macro commands into an Excel macro sheet:
+---+----------------------------------------------------------------+ | | A | +---+----------------------------------------------------------------+ | 1 | aveymd | +---+----------------------------------------------------------------+ | 2 | =ARGUMENT("start",64) | +---+----------------------------------------------------------------+ | 3 | =ARGUMENT("end",64) | +---+----------------------------------------------------------------+ | | =ROUND(AVERAGE(YEAR(end)-YEAR(start)-IF((MONTH(end) | | 4 | <MONTH(start))+(MONTH(end)=MONTH(start))*(DAY(end) | | | <DAY(start)),1)),1)&"y " | +---+----------------------------------------------------------------+ | 5 | =ROUND(AVERAGE(MONTH(end)-MONTH(start)+(MONTH(end) | | | <MONTH(start))*12-(DAY(end)<DAY(start))),0)&"m " | +---+----------------------------------------------------------------+ | 6 | =ROUND(AVERAGE(end-DATE(YEAR(end),MONTH(end)-(DAY(end) | | | <DAY(start)),DAY(start))),0)&"d" | +---+----------------------------------------------------------------+ | 7 | =RETURN(A4&A5&A6) | +---+----------------------------------------------------------------+Note: The formulas in A4, A5, and A6 must be "COMMAND+ENTERed" (instead of pressing RETURN on the main keyboard after typing the formula, hold down the COMMAND key and press the ENTER key on the numeric keypad). Define the commands as a function macro:
For example, if the start dates are in cells A2:A10 and the end dates are in cells B2:B10, the formula is
=Macro1!aveymd(A2:A10,B2:B10)where "Macro1" is the name of the macro sheet containing the macro.
|
Additional query words: 1.00 1.03 1.04 1.06 1.50 2.20 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |