XL98: Alternative EOMONTH Worksheet and Macro Functions (192277)



The information in this article applies to:

  • Microsoft Excel 98 Macintosh Edition

This article was previously published under Q192277

SUMMARY

In Microsoft Excel 98 Macintosh Edition, 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.

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.

Visual Basic for Applications Example

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements. You can use the following Visual Basic for Applications function to duplicate the functionality of the EOMONTH function:
   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 the EOMONTH function, click the Office Assistant, type eomonth, click Search, and then click to view "EOMONTH."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

179216 OFF98: How to Use the Microsoft Office Installer Program


Modification Type:MajorLast Reviewed:6/17/2005
Keywords:kbdtacode kbhowto KB192277