I’ve just had a similar problem creating lookup tables for historical interest rates based on the number of months since a transaction to the present day. I first used DateDif based formulae, but the behaviour is awkward in the same way that others have noted, based on the internal treatment of month ends for the count.
I eventually found that DateDif is not documented in Excel, it is a legacy function, and there is no easy way to fix these issues that handles all the edge cases.
For my purposes, I found a workable solution using YEARFRAC as the basic element. This gives me an “exact” value from which I can derive a “number of months” integer as follows:
Months = ROUND(((YEARFRAC(start date,end date,1))*12),0)
Yearfrac has a 3rd parameter that changes the counting convention - 1 seems to be the most sensible value.
I used this to drive a lookup table with months going back over 20 years, and I found that it always gave me the correct lookup result - so I feel fairly confident that it will serve your purpose.
The other way to approach this for short periods of time would be to count days and then convert to months via a number-of-days-in-month lookup table, in which you can control how you want to handle part months etc. Looking at the detailed behaviour of the internal functions and finance industry discussions of the issues caused by different accountancy conventions is a real eye-opener!
hope this helps.
Miles