Month -End Formula in VB

  • Thread starter Thread starter Hande & Tolga
  • Start date Start date
H

Hande & Tolga

We need to set the date of the month-end to a varaiable.
This function exists in excel EOMONTH but could not
achieve that in VB. We would like to know if there is
such a fuction or could be achieved with something else.
 
Try this function.

Function MonthEnd(Month As String, Year As String) As Date
Dim MonthStart As Date

MonthStart = CDate("01 " & Month & " " & Year)
MonthEnd = DateAdd("m", 1, MonthStart) - 1

End Function

It takes in the month and year as strings, so you can use
2, 02, Feb or February for the month and 2 or 4 digits for
the year.

HTH
Helen
 
Function datEOM(datStartDate As Date, intNumMonths As Integer) As Date

Dim intIncrementYear As Integer
Dim intYear As Integer
Dim intMonth As Integer

intIncrementYear = Int((Month(datStartDate) + intNumMonths) / 12)
intYear = Year(datStartDate) + intIncrementYear
intMonth = Month(datStartDate) + intNumMonths + 1
If intMonth > 12 Then intMonth = intMonth Mod 12

datEOM = DateSerial(intYear, intMonth, 1) - 1

End Function
 
Back
Top