View Single Post
  #6   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.

<snip

What I'm trying to do is, extracting the day's trading stock prices for a
particular stock (say APA), and assembling the data in the file newdata.csv,
over a number of years. I've included the codes below. With your new codes
I'm now able to automate the process. It fetches and opens the files
correctly. However, with sight unseen, I am not able to close the file as I
am not able to tell which was the last file it had open. Secondly, when
doing it manually, if it had found the wrong code, like "APAO" instead of
"APA", I would simply ask it to find it again until I could see that it was
the right one before proceeding. Is there a way to test this? Thanks for any
suggestions.

Sub Build_Data()
'
' Build_Data Macro
' Macro recorded 29/12/2006 by Tom
'

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

' Workbooks.Open Filename:="D:\Echart\Download\newdata.csv", Origin:= _
xlWindows
Workbooks.Open Filename:="D:\Echart\Download\newdata.csv"
Range("A1").Select
For dCtr = 1 To 10 'some big number
myDate = dCtr - 1 + DateSerial(2006, 12, 11)
If Weekday(myDate) = vbSaturday _
Or Weekday(myDate) = vbSunday Then
'do nothing
Else
myStr = "D:\Echart\Download\" & Format(myDate, "yyyymmdd") &
".txt"
Workbooks.OpenText Filename:=myStr, Origin:=437 _
, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
_
Tab:=True, Semicolon:=False, Comma:=True, FieldInfo:=Array(Array(1,
1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1)), TrailingMinusNumbers:=True
Cells.Find(What:="APA", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=
_
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate ' how to match?
ActiveCell.Range("A1:G1").Select
Selection.Copy
Windows("newdata.csv").Activate
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
Windows("20061211.txt").Activate ' how to close after looping?
Application.CutCopyMode = False
ActiveWorkbook.Close
End If
Next dCtr

End Sub