1. Month VBA function – Description
The Month VBA function returns a number representing the month of a given date. So if we want Excel VBA to return the numbers corresponding to the following months, we should use this function. It should be remembered that the date from which we want to obtain the month number should be taken from the variable or saved in the VB code in the date format, i.e. YYYY-MM-DD .
2. VBA Month Function – Syntax
Date : The date from which we want to get the next number corresponding to the month. The date should be in the YYYY-MM-DD format .
Function return: Integer / Numeric value.
3. VBA Month function – Example
How to use Month function in VBA Excel? Below is an example of using the Month function in the VisualBasic Editor.
Sub MonthFunctionExample () MsgBox Month ("2017-12-31") Dim DatDate As Date DatDate = Date MsgBox Month (DatDate) MsgBox Month (Date) Range ("A1") = Month ("2018-05-31") End Sub
4. VB Month feature – Additional information
- The date from which we want to obtain the next month number should have the Date data type or be written in the YYYY-MM-DD format.
5. Month VisualBasic function – Where to use?
The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016.
The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address: VBA functions .