depending if you want a formula or vba
assuming all the dates are in a single column like column A
=INT((MAX(A:A)-MIN(A:A))/30)
of course just calculating for 30 day months only is a bit rough, if you can use vba then datediff would be more accurate

to get the row number of the last entry for the first month, by formula, no looping required
assumes the data (date) in column A starts on row 2, change to suit
=MATCH(DATE(YEAR(A2),MONTH(A2)+1,1)-1,A:A,1)
if you want to automate moving the rows then vba could be a better option