View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 19
Default How to increment the date

"Dave Peterson" wrote in message
...
I'm not quite sure what you're doing, but if you're doing lots of dates
and want
to skip all the weekends, you could just check inside the loop and not do
the
work if it's a weekend day.

Yes. That's exactly what I'm doing. All days of the week except the weekends
and am collecting the data for several years. But I thought I would just
start looking at a week and progressively increase the investigation. I
shall now try your new codes and let you know how well it does what I want.
Thanks again, Dave.

Tom


Dim myStr As String
Dim dCtr As Long
Dim myDate As Date

For dCtr = 1 To 50 'some big number
myDate = dCtr - 1 + DateSerial(2006, 12, 11)
If Weekday(myDate) = vbSaturday _
Or Weekday(myDate) = vbSunday Then
'do nothing
Else
myStr = "C:\somepath\" & Format(myDate, "yyyymmdd") & ".txt"
'open the file named myStr
'do some work
'close that .txt file
End If
Next dCtr



Tom wrote:

This is going to save me a lot of time. Skipping the weekends, presumably
I
can next change the 11 in the dateserial to 18 and continue with the 2nd
week. However, can you create another loop to do this? Many thanks Dave.

Tom

"Dave Peterson" wrote in message
...
Dim myStr as string
dim dCtr as long
dim myDate as date

for dctr = 1 to 5
myDate = dctr - 1 + dateserial(2006,12,11)
mystr = "C:\somepath\" & format(myDate,"yyyymmdd") & ".txt"
'open the file named myStr
'do some work
'close that .txt file
next dctr


Tom wrote:

I use a macro to open the file 20061211.txt which is named after the
date,
and extract some
data before closing it. I then repeat the process and open up the next
file
20061212.txt and so on till I reach the last file 20061215.txt. I
would
like to be able to use For N =1 to 5 and Next N, to automate the
process
but
I don't know how to increment the date by one each time. Any help will
be
much appreciated.

TIA
Tom

--

Dave Peterson


--

Dave Peterson