Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to determine the number of months that are spanned in a
given period. For example, the number of months spanned in the period 16 Jun 06 to 17 Jul 06 is 2. All the functions in Excel that I have found give the result as 31 days or 1 month. I am trying to avoid creating a lookup table that lists each month of each year as the periods I need to look at will go up to and beyond 2018 (without me knowing) so ideally, the process needs to automated so there are no tables to maintain. I'd be grateful if anyone could advise how I can go about this. Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
=IF(MONTH(B1)-MONTH(A1)=0,MONTH(B1)-MONTH(A1)+1,MONTH(B1)-MONTH(A1)+1+12*(YEAR(B1)-YEAR(A1))) Note that the date in column B *must* be greater than or equal to the date in column A Regards Trevor wrote in message oups.com... I am trying to determine the number of months that are spanned in a given period. For example, the number of months spanned in the period 16 Jun 06 to 17 Jul 06 is 2. All the functions in Excel that I have found give the result as 31 days or 1 month. I am trying to avoid creating a lookup table that lists each month of each year as the periods I need to look at will go up to and beyond 2018 (without me knowing) so ideally, the process needs to automated so there are no tables to maintain. I'd be grateful if anyone could advise how I can go about this. Thanks |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for this.
It works a treat if I'm looking at a 12 month period. But it won't work for a period greater than that - unless maybe I have done something wrong.... Thanks for the base logic - I'll try playing around with it some more. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Try =DATEDIF(A1,B1,"m")+(DAY(A1)DAY(B1))+ -- daddylongleg ----------------------------------------------------------------------- daddylonglegs's Profile: http://www.excelforum.com/member.php...fo&userid=3048 View this thread: http://www.excelforum.com/showthread.php?threadid=52379 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks very much - this does just what I need.
Cheers! |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Did you try it with a period greater than 12 months ? It works for me.
That's the point of the +12*(YEAR(B1)-YEAR(A1)) part of the formula ... it adds 12 for each change of year. "happywitchie" wrote in message ups.com... Thanks for this. It works a treat if I'm looking at a 12 month period. But it won't work for a period greater than that - unless maybe I have done something wrong.... Thanks for the base logic - I'll try playing around with it some more. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Trevor
Yes, I did it try with all kinds of periods and it doesn't work on greater than 12. I'm not sure what could be the trouble as I tried both cutting and pasting the formula as you wrote it here and typing it in myself. I'm using Excel 2003 on XP if that makes a difference. But the formula that daddylonglegs just gave works well for me. Thanks for your help. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi Trevor, The TRUE part of your IF formula doesn't always give the correc result, i.e. where MONTH(B1)=MONTH(A1) but YEAR(A1) and YEAR(B1) ar 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 wor 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))+ -- daddylongleg ----------------------------------------------------------------------- daddylonglegs's Profile: http://www.excelforum.com/member.php...fo&userid=3048 View this thread: http://www.excelforum.com/showthread.php?threadid=52379 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Calculating Months within a specific period | Excel Discussion (Misc queries) | |||
Highest 12-Month Period Average Over Range of Months | Excel Worksheet Functions | |||
How do i get rid of the period in a whole number? | New Users to Excel | |||
Loan period in Months | Excel Discussion (Misc queries) | |||
number of mondays in period | Excel Discussion (Misc queries) |