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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Should be:

Code:
Function NextMonth(dat As Date)
    NextMonth = DateSerial(Year(dat), Month(dat) + 1, Day(dat))
End Function
 

Seti

Well-known Member
Joined
May 19, 2002
Messages
2,916
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,186
Messages
5,640,688
Members
417,161
Latest member
Devon150

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
Top