Question

I need to create a spreadsheet with two columns: initial month/year and final month/year. Then I have five another columns: 2009 | 2010 | 2011 | 2012 | 2013
The row below these five columns would have the number of months in the interval that fall on that year. If I have January/2009 - February/2011 the result would be:

2009 - 12
2010 - 12
2011 - 2
2012 - 0
2013 - 0

Can I do that without macros?

Was it helpful?

Solution

With dates in A2 and B2 and years only in C1 across try this formula in C2 across (and down if required)

=IFERROR(DATEDIF(MAX($A2,DATE(C$1,1,1)),MIN($B2,DATE(C$1,12,31)),"m")+1,0)

OTHER TIPS

This formula should work:

=IF(ROUNDUP(($B2-C$1)/30;0)>12;12;IF(ROUNDUP(($B2-C$1)/30;0)<0;0;ROUNDUP(($B2-C$1)/30;0)))

This formula considers you have start date in A2 and End Date in B2 both in date format and you can use custom cell format (mmmm/yyyy) so it looks like January/2009. Put this formula in C2 whose Header(cell C1) should be 2009 in date format (01-01-2009). You can use custom cell format (yyyy) so it looks like 2009.

Now drag this formula horizontally whose headers are 2010,2011 in date format respectively.

If you face any problem do let me know

Please note you might have to change the semi-colons (;) to comma (,) in the formula

Given the years in C1:g1 (alter as needed), you can try this formula:

=SUMPRODUCT(N(YEAR(EDATE(Initial_Month_Year,ROW(INDIRECT("1:" &1+DATEDIF(Initial_Month_Year,Final_Month_Year,"m")))-1))=C$1))

Enter it in some cell, e.g. C2, and fill to the right as far as needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top