Thread: trapping error
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
RobcPettit RobcPettit is offline
external usenet poster
 
Posts: 12
Default trapping error

Sub ToManyPrices()
I can not seem to get this Error trap to work, when I find the first file that
is not in the directory my msgbox works, when I find a 2nd file that is not in
the dir the program crashes, could you advise why.

Application.Goto Reference:="Dates2"
Collectdat = Range("Dates2").Value
If Range("f8") < "" Then
BeYondDate = Range("f7", Range("f7").End(xlDown)) ' this gets the list of files
to look for
Range("f8", Range("f8").End(xlDown)).Clear
Else
Exit Sub
End If

For i =1 To UBound(BeYondDate)

On Error GoTo Nofile
Workbooks.OpenText Filename:="I:\My Documents\sharescope export\" &
BeYondDate(i, 1) & ".prn", _
Origin:=xlMSDOS, StartRow:=2, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1),
_
Array(2, 1), Array(3, 9), Array(4, 9), Array(5, 9), Array(6, 1),
Array(7, 9)), _
TrailingMinusNumbers:=True

Name = Range("a1") 'epic

Importdat = Range("b1", Range("c1").End(xlDown)) 'shares dates

Workbooks(BeYondDate(i, 1) & ".prn").Close False 'closes share file
comparedat


Nofile:
MsgBox ("File " & "'" & BeYondDate(i, 1) & "'" & " not found in Sharescope
Export")


Next i

End Sub