Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"num#" errors .. how to average a group with a "num#" error Byron Excel Discussion (Misc queries) 3 May 20th 09 04:32 AM
"Document not saved" "error in loading DLL" Tracey L Excel Discussion (Misc queries) 0 December 1st 08 12:57 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Shortcut key for "Paste Options" and "Error Checking" buttons? johndog Excel Discussion (Misc queries) 1 October 6th 06 11:56 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"