UDF Date Function

Shamsuddeen

Active Member
Joined
Feb 16, 2002
Messages
292
Hi all!...


I have the following UDF to return the given date with one month advanced.



Function NextMonth(dat as date)

NextMonth = Date(year(dat),month(dat)+1,day(dat))

End Function


But the second line of the UDF gives an error.

Could someone help?

Shamsuddeen
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Should be:

Code:
Function NextMonth(dat As Date)
    NextMonth = DateSerial(Year(dat), Month(dat) + 1, Day(dat))
End Function
 
Upvote 0
Date is not a VBA function, it is the system date. Try DateSerial instead. You will have problems at the ends of months though. Try using 1/31/2004 as the input to your function and you get back 3/2/2004 since the 31st is not a valid date in February, so it moves to 31 days after 1/31/2004.
 
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,661
Members
449,247
Latest member
wingedshoes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top