XL: Alternative EOMONTH Worksheet and Macro Functions

Last reviewed: February 2, 1998
Article ID: Q123189
The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 4.0a, 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 1.5, 2.2, 3.0, 4.0, 5.0, 5.0a
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows
  • Microsoft Excel 98 Macintosh Edition

SUMMARY

In Microsoft Excel, you can duplicate the functionality of the EOMONTH function, which is available in the Analysis ToolPak add-in, either by combining worksheet functions or by creating a user-defined function procedure.

Note that the Analysis ToolPak add-in is not included in versions of Microsoft Excel earlier than 4.0.

MORE INFORMATION

The EOMONTH function has two arguments: a start date and the number of months to count ahead from the start date. The second argument can be positive, zero, or negative. The result is a serial date value equal to the last day of the specified month.

Worksheet Function

The following worksheet function duplicates the functionality of the EOMONTH function. This example assumes that the date "1/1/98" is entered in cell A1. The formula =EOMONTH(A1,1) is equivalent to the following:

   =DATE(YEAR(A1),MONTH(A1)+1,1)-1

Both functions return the value 1/31/98. This function calculates a date equal to the first day of the month that is one month greater than the date you are trying to obtain, then subtracts one day from that date, yielding the last day of the month in question.

Code Examples

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/supportnet/refguide/ 

Excel 4.0 Macro Function:

The following macro works in all versions of Microsoft Excel:

   A1: MyEoMonth
   A2: =ARGUMENT("startDate",1)
   A3: =ARGUMENT("months",1)
   A4: =RETURN(DATE(YEAR(startDate),MONTH(startDate)+months+1,1)-1

Visual Basic for Applications Function:

The following Visual Basic for Applications function procedure works in Microsoft Excel versions 5.0 and later:

   Function MyEoMonth(startDate As Date, months As Integer)
       MyEoMonth = _
           DateSerial(Year(startDate), Month(startDate) + months + _
           1, 1) - 1
   End Function

REFERENCES

For more information about EOMONTH, choose the Search button in Help and type:

   EOMONTH function


Additional query words: 1.50 2.10 2.20 3.00 4.00 4.00a 5.00 5.00c 7.00
7.00a 97 98 XL98 XL97 XL7 XL5 XL4 XL3
Keywords : xllist
Version : WINDOWS:4.0,5.0,7.0,7.0a,97; MACINTOSH:4.0,5.0,98
Platform : MACINTOSH WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.