Option Explicit
Function TaySeries(x, Error)
Dim AddSum, TotSum, n As Single
TotSum = 0
For n = 1 To 100
AddSum = (-1) ^ (n + 1) * (1 / n) * (x - 2) ^ n
TotSum = TotSum + AddSum
If (AddSum / TotSum) < Error Then n = 101
Next
TaySeries = TotSum
End Function
To clear the error we use On Error GoTo -1. Think of it like setting a mouse trap. When the trap goes off you need to set it again.
In the code below we add this line and the second error will now cause the code to jump to the eh_other label
Sub TwoErrors()
On Error Goto eh
' generate "Type mismatch" error
Error (13)
Done:
Exit Sub
eh:
' clear error
On Error Goto -1
On Error Goto eh_other
' generate "Application-defined" error
Error (1034)
Exit Sub
eh_other:
Debug.Print "eh_other " & Err.Description
End Sub
Get Answers For Free
Most questions answered within 1 hours.