Friday, August 12, 2016

How to use the MONTH Function (WS,VBA)

Description

The Microsoft Excel MONTH function returns the month (a number from 1 to 12) given a date value. The MONTH is both a worksheet function and a VBA function.
Microsoft Excel
If you want to follow along with this tutorial, download the example spreadsheet.

Syntax

The syntax for the MONTH function in Microsoft Excel is:
MONTH( date_value )

Parameters or Arguments

date_value
A valid date to return the month.

Applies To

  • Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • Worksheet function (WS)
  • VBA function (VBA)

Example (as Worksheet Function)

Let's look at some Excel MONTH function examples and explore how to use the MONTH function as a worksheet function in Microsoft Excel:
Microsoft Excel
Based on the Excel spreadsheet above, the following MONTH examples would return:
=MONTH(B2)
Result: 9

=MONTH(B3)
Result: 8

=MONTH(B4)
Result: 4

=MONTH("12/31/2011")
Result: 12

Example (as VBA Function)

The MONTH function can also be used in VBA code in Microsoft Excel.
Let's look at some Excel MONTH function examples and explore how to use the MONTH function in Excel VBA code:
Dim LMonth As Integer

LMonth = Month("12/31/2001")
In this example, the variable called LMonth would now contain the value of 12.

Frequently Asked Questions

Question: Can you help me with a formula for the following: I want cell C1 to return the value from cell B1 if cell A1 falls in January (ie: Jan 1 - Jan 31).
Answer: In cell C1, you can write your formula using the IF function and the MONTH function as follows:
=IF(MONTH(A1)=1,B1,"")
In this formula, if MONTH(A1) returns 1, then cell A1 falls in January and will return the value from B1.