ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Function in Excel (https://www.excelbanter.com/excel-programming/431527-function-excel.html)

[email protected]

Function in Excel
 
I am looking to use a function in VBA like =DATE(YEAR(NOW())-1,MONTH
(NOW()),DAY(NOW()))

How can I do this?

I tried: Application.WorksheetFunction.Date(Year(Now()) - 1, Month(Now
()), Day(Now())) without success.

Thanks.

Mike H

Function in Excel
 
Hi,

Try this

mynewtime = Format(DateAdd("yyyy", -1, Now), "dd/mm/yyyy")

Mike

" wrote:

I am looking to use a function in VBA like =DATE(YEAR(NOW())-1,MONTH
(NOW()),DAY(NOW()))

How can I do this?

I tried: Application.WorksheetFunction.Date(Year(Now()) - 1, Month(Now
()), Day(Now())) without success.

Thanks.


Matthew Herbert

Function in Excel
 
On Jul 24, 9:08*am, "
wrote:
I am looking to use a function in VBA like =DATE(YEAR(NOW())-1,MONTH
(NOW()),DAY(NOW()))

How can I do this?

I tried: Application.WorksheetFunction.Date(Year(Now()) - 1, Month(Now
()), Day(Now())) without success.

Thanks.


Michael,

Use DateSerial.

Best,

Matthew Herbert

Dim myDate As Date
myDate = DateSerial(Year(Date) - 1, Month(Date), Day(Date))


All times are GMT +1. The time now is 12:10 PM.

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