Table of Contents
The EoMonth function in VBA (Visual Basic for Applications) is a useful tool that allows users to find the end of a specified month. This function takes two arguments: a date and a number of months. It then returns the last day of the month that is the specified number of months after the given date. This is particularly useful for financial analysis, project planning, and data organization.
For example, if you have a project start date of January 1, 2021, and you want to find the end date of the project, which is six months later, you can use the EoMonth function. By inputting the date as 01/01/2021 and the number of months as 6, the function will return the end date of the project as June 30, 2021. This allows for quick and accurate calculation of end dates for various projects and tasks.
In addition, the EoMonth function can also be used to find the end date of a financial quarter or year. By inputting the first day of the quarter or year and using the appropriate number of months, the function will return the last day of that quarter or year.
In summary, the EoMonth function in VBA is a versatile and efficient tool for finding the end of a specified month, quarter, or year. Its ability to quickly calculate end dates makes it a valuable function for various tasks and projects.
Use EoMonth in VBA (With Example)
You can use the EoMonth method in VBA to return the last day of the month for a given date.
Here is one common way to use this method in practice:
Sub LastDayOfMonth()
Dim i As Integer
For i = 2 To 11
Range("C" & i).Value = Application.WorksheetFunction.EoMonth(Range("A" & i), 0)
Range("C" & i).NumberFormat = "m/d/yyyy"
Next i
End Sub
This particular macro finds the last day of the month for each date in the range A2:A11 and displays this date in the corresponding cell in the range C2:C11.
The following example shows how to use this syntax in practice.
Example: How to Use EoMonth in VBA
Suppose we have the following dataset in Excel that contains information about the sales made by some company on various dates:

Suppose we would like to find the last day of the month for each date in column A and display it in column C.
We can create the following macro to do so:
Sub LastDayOfMonth()
Dim i As Integer
For i = 2 To 11
Range("C" & i).Value = Application.WorksheetFunction.EoMonth(Range("A" & i), 0)
Range("C" & i).NumberFormat = "m/d/yyyy"
Next i
End SubWhen we run this macro, we receive the following output:

Notice that column C contains the last day of the month for each corresponding date in column A.
Note that we used the NumberFormat property to display the date values in a recognizable date format in column C instead of serial numbers, which is the default format in Excel.
Also note that the last argument of the EoMonth method specifies how many months ahead or behind to use when calculating the last day of the month.
In this example we used a value of 0 to specify that we’d like to find the last day of the current month.
Note: You can find the complete documentation for the EoMonth method in VBA .
Cite this article
stats writer (2024). How can I use the EoMonth function in VBA?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-the-eomonth-function-in-vba-with-an-example/
stats writer. "How can I use the EoMonth function in VBA?." PSYCHOLOGICAL SCALES, 21 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-the-eomonth-function-in-vba-with-an-example/.
stats writer. "How can I use the EoMonth function in VBA?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-the-eomonth-function-in-vba-with-an-example/.
stats writer (2024) 'How can I use the EoMonth function in VBA?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-the-eomonth-function-in-vba-with-an-example/.
[1] stats writer, "How can I use the EoMonth function in VBA?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use the EoMonth function in VBA?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
