This seems to do what you want:
=IF(B5>DATE(2012,12,31),12,IF(B5<DATE(2012,1,1),0,MONTH(B5)))-IF(A5>DATE(2012,12,31),0,IF(A5<DATE(2012,1,1),0,MONTH(A5)-1))
although it returns 4 for your third example (1/05/2012 to 31/08/2012) instead of 3. However, if you count the months in that range you will find that there are 4. The formula will count part months as whole months, so 31/01/2012 to 1/03/2012 will return 3.
Hope this helps.
Pete
Bookmarks