Summary: I want to do some basic error-handling
Problem: When I step through the code my “Error” block data gets run even when there isn’t an error
-I’m pretty new to error handling in VBA and don’t understand why the code in the Error block is run aside from me directing the code to enter the block. Thanks in Advance!
Code:
Function getReports()
startJournal = Sheets("Runsheet").Range("B5")
endJournal = Sheets("Runsheet").Range("E5")
If startJournal = 0 Or endJournal = 0 Then
GoTo Error
End If
'bunch of code
Error:
MsgBox ("Error Statement")
End Function
You need
Exit Functionbefore the error label.i.e. the code should hit the label (eh) only in case of error & exit otherwise.
Looking at your code, you could write it as
On the caller’s side