Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Use of "On Error" within a loop
Hi
I am using the following code (abbreviated) to extract data from daily statistics files. For various reasons we may not get a file for every day of the month. It works when all files exist, or when one stats file is missing. If two files are missing then I get an "Error 1004 .... file could not be found" message when attempting to open the second missing file. For i = 1 To 31 On Error GoTo NoBook Workbooks.Open Filename:="stats_day" & i & ".csv" ' 'process data from the opened workbook ' NoBook: Next i I'm sure there will be a simple explanation, but I am stummped. Thanks for your help Alastair |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Use of "On Error" within a loop
Alastair,
Try: For i = 1 To 31 On Error GoTo NoBook Workbooks.Open Filename:="stats_day" & i & ".csv" ' 'process data from the opened workbook ' A100: Next i ....... ....... ....... Exit Sub NoBook: Resume A100 End Sub The "Resume" statement clears the error condition. Without it, the error handler fails on the second error condition after handling the first. Alex "Alastair" wrote in message om... Hi I am using the following code (abbreviated) to extract data from daily statistics files. For various reasons we may not get a file for every day of the month. It works when all files exist, or when one stats file is missing. If two files are missing then I get an "Error 1004 ... file could not be found" message when attempting to open the second missing file. For i = 1 To 31 On Error GoTo NoBook Workbooks.Open Filename:="stats_day" & i & ".csv" ' 'process data from the opened workbook ' NoBook: Next i I'm sure there will be a simple explanation, but I am stummped. Thanks for your help Alastair |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
"num#" errors .. how to average a group with a "num#" error | Excel Discussion (Misc queries) | |||
"Document not saved" "error in loading DLL" | Excel Discussion (Misc queries) | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
Shortcut key for "Paste Options" and "Error Checking" buttons? | Excel Discussion (Misc queries) | |||
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next | New Users to Excel |