View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Calculating the end of the month

Hi mastermind,

The first of next month can be determined by getting the "0" day for the
next month. Here's a function that should work for you. Just pass in the
current date, and it will return the next date:

Public Function gdtGetNextPeriodEnd(rdtCurrentPeriodEnd _
As Date) As Date
If Day(rdtCurrentPeriodEnd) = 15 Then
gdtGetNextPeriodEnd = DateSerial(Year( _
rdtCurrentPeriodEnd), Month(rdtCurrentPeriodEnd) _
+ 1, 0)
Else
gdtGetNextPeriodEnd = DateSerial(Year( _
rdtCurrentPeriodEnd), Month(rdtCurrentPeriodEnd) _
+ 1, 15)
End If
End Function

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

mastermind wrote:
I have a sheet that needs to be able to alternate between the 15th and
last day of each month. The user will enter a start date, and I need
the code to start at this point and jump to the next date. Example:


Start date: 01/15/06
run code
date: 01/31/06
run code
date: 02/15/06
run code
date: 02/28/06

and so on. Can anyone help me with this problem? Thank you.