ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Changing Dates (https://www.excelbanter.com/excel-programming/349297-changing-dates.html)

IanC

Changing Dates
 
I am looking to programmatically move a date forward or back by whole months
(i.e. 3, 6, or 9) - the sort of process carried out by Edate if used in a
formula. However, Edate doesn't seem to be available for use in VBA code.

Am I missing something or is there a different way around this.

Thanks in advance.

Toppers

Changing Dates
 
Ian,
Look at VBA "DateAdd" function.

Code from VBA help ...


Dim FirstDate As Date ' Declare variables.
Dim IntervalType As String
Dim Number As Integer
Dim Msg
IntervalType = "m" ' "m" specifies months as interval.
FirstDate = InputBox("Enter a date")
Number = InputBox("Enter number of months to add")
Msg = "New date: " & DateAdd(IntervalType, Number, FirstDate)
MsgBox Msg

HTH

"IanC" wrote:

I am looking to programmatically move a date forward or back by whole months
(i.e. 3, 6, or 9) - the sort of process carried out by Edate if used in a
formula. However, Edate doesn't seem to be available for use in VBA code.

Am I missing something or is there a different way around this.

Thanks in advance.


Bob Phillips[_6_]

Changing Dates
 
Ian,

Just set a reference to APTVBAEN.XLA in the VBIDE and you can then
programmatically use the ATP functions like

MsgBox Format(EDATE(Date, -3), "dd mmm yyyy")


--

HTH

RP
(remove nothere from the email address if mailing direct)


"IanC" wrote in message
...
I am looking to programmatically move a date forward or back by whole

months
(i.e. 3, 6, or 9) - the sort of process carried out by Edate if used in a
formula. However, Edate doesn't seem to be available for use in VBA code.

Am I missing something or is there a different way around this.

Thanks in advance.




IanC

Changing Dates
 
Spot on. Thank you very much.

"Toppers" wrote:

Ian,
Look at VBA "DateAdd" function.

Code from VBA help ...


Dim FirstDate As Date ' Declare variables.
Dim IntervalType As String
Dim Number As Integer
Dim Msg
IntervalType = "m" ' "m" specifies months as interval.
FirstDate = InputBox("Enter a date")
Number = InputBox("Enter number of months to add")
Msg = "New date: " & DateAdd(IntervalType, Number, FirstDate)
MsgBox Msg

HTH

"IanC" wrote:

I am looking to programmatically move a date forward or back by whole months
(i.e. 3, 6, or 9) - the sort of process carried out by Edate if used in a
formula. However, Edate doesn't seem to be available for use in VBA code.

Am I missing something or is there a different way around this.

Thanks in advance.



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

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