ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calculating Dates in VBA (https://www.excelbanter.com/excel-programming/290962-calculating-dates-vba.html)

Squid[_2_]

Calculating Dates in VBA
 
I want to write some code that will calculate a date. I
need to calcuate an expiration date. The expiration date
will always be 1 year minus a day from the effective
date. So if the effective date = 6/1/2003, then the
expiration date = 5/31/04. I can do this pretty easily
within an excel worksheet, but I would like this to
happen with code.

Thanks
Mike



Juan Pablo González

Calculating Dates in VBA
 
Its actually quite easy in VBA. A function like this for example:

Function ExpirationDate(StartDate As Date) As Date
ExpirationDate = DateAdd("yyyy", 1, StartDate) - 1
End Function

Used like:

?ExpirationDate(DateSerial(2003,6,1))
5/31/2004


--
Regards,

Juan Pablo González

"Squid" wrote in message
...
I want to write some code that will calculate a date. I
need to calcuate an expiration date. The expiration date
will always be 1 year minus a day from the effective
date. So if the effective date = 6/1/2003, then the
expiration date = 5/31/04. I can do this pretty easily
within an excel worksheet, but I would like this to
happen with code.

Thanks
Mike





Squid[_3_]

Calculating Dates in VBA
 
Thank you... knew if was simple. .


"Juan Pablo González" wrote in message
...
Its actually quite easy in VBA. A function like this for example:

Function ExpirationDate(StartDate As Date) As Date
ExpirationDate = DateAdd("yyyy", 1, StartDate) - 1
End Function

Used like:

?ExpirationDate(DateSerial(2003,6,1))
5/31/2004


--
Regards,

Juan Pablo González

"Squid" wrote in message
...
I want to write some code that will calculate a date. I
need to calcuate an expiration date. The expiration date
will always be 1 year minus a day from the effective
date. So if the effective date = 6/1/2003, then the
expiration date = 5/31/04. I can do this pretty easily
within an excel worksheet, but I would like this to
happen with code.

Thanks
Mike








All times are GMT +1. The time now is 07:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com