Thursday, July 12, 2007

VBA test - adding dates

I'm just setting up my template at the moment to handle VBA formatting - and I thought it might be a good test to use a practical example. The following code is used to add dates in VBA:

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


The "m" used here to signify "months" could also be substituted out as one of the following:
yyyy Year
q    Quarter
m    Month
y    Day of year
d    Day
w    Weekday
ww   Week
h    Hour
n    Minute
s    Second

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home