Month -End Formula in VB

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.
 
H

Helen Trim

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
 
D

Dianne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top