DateSerial function

  • Thread starter Thread starter inungh
  • Start date Start date
I

inungh

I would like to calculate rollong calendar from today in the loop.

For example, today is Dec/11/2008 and I need to get all informaiton 12
months before today. (from Dec/11/2007 to Dec/11/2008).

I just wonder can DateSerila do the job.

For example, DateSerial(MyYear, MyMonth - i, MyDay)

Will DateSerial changed the year if the month is minus number?

Your information is great appreciated,
 
Are you attempting to construct a loop that will iterate through each day of
the previous 12 months? If so, you can do that directly in the For statement
of your For..Next loop. Consider this (and notice that D is declared as
Date)...

Sub Test()
Dim D As Date
For D = DateAdd("m", -12, Date) To Date
Debug.Print D
Next
End Sub

The above code will print the date for each day for the previous year...
just replace it with the code you actually want to operate on those days.
 
And to answer your question directly, yes, DateSerial will properly handle
the year when the month goes negative.
 
And to answer your question directly, yes, DateSerial will properly handle
the year when the month goes negative.

--
Rick (MVP - Excel)








- Show quoted text -

Thanks millions,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top