|
|
|
|
|
|
Excel
|
Return number of days in a given month; Function
|
|
Ease of Use
|
Easy
|
Version tested with
|
2002, 2003
|
Submitted by:
|
Zack Barresse
|
Description:
|
This function will return the number of days for a given month. The month needs to be given as a numeric (1-12).
|
Discussion:
|
The need may arise to return the number of days in a month for calculations. This can be done with native functions, but this is a much more condensed version and can save formula real-estate.
|
Code:
|
instructions for use
|
Option Explicit
Public Function MonthDays(myMonth As Long) As Long
MonthDays = Day(DateSerial(Year(Date), myMonth + 1, 1) - 1)
End Function
|
How to use:
|
- Copy above code.
- In Excel press Alt + F11 to enter the VBE.
- Press Ctrl + R to show the Project Explorer.
- Right-click desired file on left (in bold).
- Choose Insert -> Module.
- Paste code into the right pane.
- Press Alt + Q to close the VBE.
- Save workbook before any other changes.
|
Test the code:
|
- Install the code.
- Save workbook.
- In a blank cell, enter "=MonthDays(1)"
- Replace the number 1 with the desired month number.
|
Sample File:
|
MonthDaysEx.zip 7.92KB
|
Approved by mdmackillop
|
This entry has been viewed 207 times.
|
|