Error Handling construct
The real question was about error handling and I just put Find in to
illustrate.
However this is what I am doing with the real find. At this stage in the
project the code is simply establishing whether any of the possible
descriptions for salutation is in data pulled from an unopened workbook and
added to the xla wsheet for scrutiny. If found, a value is given for
assessment. There are other groups of alternatives for other headers in the
table. If all tests are passed then that particular workbook is passed for
further processing.
Geoff
Dim rnum as Long
Dim headertbl As Range
Dim foundSalutation As String
Dim realLastColumn As Long
With Sheets(1)
Set headertbl = .Range(.Cells(rnum + 1, 2), .Cells(rnum + 1, .Range("IV" &
rnum + 1).End(xlToLeft).Column))
foundSalutation = headertbl.Find("Title", , , xlWhole)
foundSalutation = headertbl.Find("Salutation", , , xlPart)
foundSalutation = headertbl.Find("Honorific", , , xlPart)
foundSalutation = headertbl.Find("Prefix", , , xlPart)
foundSalutation = headertbl.Find("Name", , , xlWhole)
If Not foundSalutation = "" Then .Cells(rnum + 1, realLastColumn).Offset(,
2) = 16
End With
"Dave Peterson" wrote:
If your real question is about error handling, ignore this response.
But if you're real question is about using .find:
Option Explicit
Sub Main()
Dim FoundIt as Range
'I'd specify all the parms--I wouldn't want to use the
'parms from VBA's last find or the user's last find.
'and don't forget the Set statement
set foundit = Sheets(1).Find("xxx", , , xlWhole)
if foundit is nothing then
'not found
else
'was found
end if
End Sub
Geoff wrote:
Hi
From tests and 'Help' it seems I need to restate On Error GoTo
myErrorHandler after returning from each sub proc and after the On Error
Resume Next.
Is that correct or is there a better way to provide error handling
throughout Main?
T.I.A.
Geoff
Sub Main()
On Error GoTo myErrorHandler
blah
SubProc1 ''no error handler in this proc
On Error Resume Next
foundIt = Sheets(1).Find("xxx", , , xlWhole)
On Error GoTo 0
SubProc2 ''no error handler in this proc
blah
Exit Sub
myErrorHandler:
If Err.Number < 0 Then
'''do something
Err.Clear
End If
End Sub
--
Dave Peterson
|