View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Trevor Shuttleworth Trevor Shuttleworth is offline
external usenet poster
 
Posts: 1,089
Default number of months in a period

Thanks for working it through for me ;-(

I went through a few iterations to get to that formula as I realised I
needed to cater for going across the end of year(s) boundary ... just didn't
test ALL the variations.

It worked for everything I DID test ;-)

Oh well, you live and learn ... even though sometimes you embarrass yourself
!

Your "revision" of my formula was much neater ... but your own was better.

Regards ... and thanks again

Trevor


"daddylonglegs"
wrote in message
news:daddylonglegs.24vjtb_1142700602.2947@excelfor um-nospam.com...

Hi Trevor,

The TRUE part of your IF formula doesn't always give the correct
result, i.e. where MONTH(B1)=MONTH(A1) but YEAR(A1) and YEAR(B1) are
different. E.g.

A1 is 01/01/2005
B1 is 02/02/2006

result should be 14

=IF(MONTH(B1)-MONTH(A1)=0,MONTH(B1)-MONTH(A1)+1,MONTH(B1)-MONTH(A1)+1+12*(YEAR(B1)-YEAR(A1)))

gives 2.

You only actually need the final part of your formula, that will work
in all cases (where date in B1 is later than or equal to date in A1),
i.e.

=MONTH(B1)-MONTH(A1)+12*(YEAR(B1)-YEAR(A1))+1


--
daddylonglegs
------------------------------------------------------------------------
daddylonglegs's Profile:
http://www.excelforum.com/member.php...o&userid=30486
View this thread: http://www.excelforum.com/showthread...hreadid=523795