View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default Summation of months or years

On Nov 3, 11:34*pm, Sandeep Nair <Sandeep
wrote:
How can i add months or years and get the answer
in the same format. For example, adding 2 years
10 months and 1 year 3 months. The answer should
be 4 years 1 month. If we do this calculation in
excel, as usual it will give the answer as 3.13
(2.10+1.3).


First, year/month values of this form should be entered as text, not
numbers; for example '2.10 and '1.3 (the first character is an
apostrophe, aka single quote). Otherwise, we cannot distinguish
between 2y 10m and 2y 1m, for example.

Assuming you do that, the following adds 2 such values in A1 and A2:

1. In a helper cell (A3), put:

=LEFT(A1,FIND(".",A1)-1)
+ RIGHT(A1,LEN(A1)-FIND(".",A1))/12
+ LEFT(A2,FIND(".",A2)-1)
+ RIGHT(A2,LEN(A2)-FIND(".",A2))/12

2. In another cell, compute the year/month result by:

=INT(A3) & "." & INT(MOD(A3,1)*12)

Of course, you could do it all in one cell, replacing each instance of
A3 with the formula in A3 (gulp!).

Alternatively (double gulp!):

=LEFT(A1,FIND(".",A1)-1) + LEFT(A2,FIND(".",A2)-1)
+ INT((RIGHT(A1,LEN(A1)-FIND(".",A1))
+ RIGHT(A2,LEN(A2)-FIND(".",A2)))/12)
& "." &
MOD((RIGHT(A1,LEN(A1)-FIND(".",A1))
+ RIGHT(A2,LEN(A2)-FIND(".",A2))), 12)