Guys,
The following code gives the 1004 "Application-defined or
object-defined error" error when is inside a function:
Function myFunction() As Integer
myFunction = 0
On Error GoTo Error
Worksheets(1).Range("B2").Value = 3.14159
Exit Function
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error
in myFunction"
myFunction = -1
End Function
But the same code works inside a sub:
Sub mySub()
On Error GoTo Error
Worksheets(1).Range("B2").Value = 3.14159
Exit Sub
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error
in mySub"
End Sub
I can't figure out why and can't work around it. Does anyone have any
ideias? Any help would be deeply appreciated.
Thanks in advance!
Bookmarks