Excel & vba: quanti giorni ha un mese?

Direttamente da mamma Microsoft la soluzione a questo annoso dilemma:

Function DaysInMonth(MyDate) As Long

Dim NextMonth As Date
Dim EndOfMonth As Date
NextMonth = DateAdd("m", 1, MyDate)
EndOfMonth = NextMonth - DatePart("d", NextMonth)
DaysInMonth = DatePart("d", EndOfMonth)

End Function

Va al primo giorno del mese successivo e poi toglie un giorno. Genialacci.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>