LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default On Errror Goto Error handler only works first time through "For Each" cycle

Where's my bug? I have a nice module for selecting a range of cells
in workbookA, opening a workbookB based on the cell contents, and
transferring some data back to workbook A. If one of the selected
cells is not an appropriate entry, I have an error handler set up to
give a little message and move on to the next cell. The problem is
that the error handler only works once! If a given cell triggers the
error handler, it routes properly to my message box and then on to
process the next cell in the selection. But if a second cell is
"improper", the error handler is not triggered, and the resulting
error message terminates the module. I have already tried getting rid
of the "On Error Goto 0" to end error trapping, that didn't make any
difference. (Not that I thought it should, because error trapping
should be reinitiated the next cycle through the "For Each" statement,
right?)

here's some (simplified) code:

Set MyRange = Selection

For each cell in MyRange.Cells
MyRow = cell.row
MySampleName = Cells(MyRow, 2).Value
MyPath = "\\c\data\" & MySampleName & ".xls"

On Error GoTo Errorhandler
Workbooks.Open Filename:=MyPath
On Error GoTo 0

'...here is a bunch of data manipulation, works fine, not interesting

NextCell:
Next Cell
Exit Sub
Errorhandler:
MsbBox "Not a valid Sample Name."
GoTo NextCell
End Sub

 
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
Question on "On Error GoTo skip" dan Excel Discussion (Misc queries) 2 July 1st 07 10:48 PM
"On Error GoTo" syntax problem jonrayworth Excel Programming 1 July 1st 06 01:16 AM
Can I place "On Error GOTO xxx" into module level? Frederick Chow Excel Programming 2 January 4th 06 04:03 AM
Subroutine vs GOTO "On Error" Bob Phillips[_6_] Excel Programming 0 July 14th 05 10:12 PM


All times are GMT +1. The time now is 07:31 AM.

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"