The best way to debug a user defined function (UDF) is by writing a temporary Sub procedure that calls your function and then step into the Sub procedure by pressing F8 key.
Example :
UDF -
Example :
UDF -
Function grade(score As Single, score1 As Single) As StringTemporary Sub Procedure -
If score >= 75 And score1 >= 75 Then
grade = "A"
ElseIf score > 50 And score1 > 50 Then
grade = "B"
Else
grade = "C"
End If
End Function
Sub test()
MsgBox grade(Range("A2").Value, Range("B2").Value)
End Sub
Next Step : Position your cursor before Sub test() and then press F8 key to step into the Sub Procedure.
Perfect and simple solution. Thanks. Gary
ReplyDeleteThanks - this was helpful!
ReplyDeleteThanks. It works.
ReplyDeleteStepping into my function as described works, but calling it from the spreadsheet throws a #Name? error. Confused on why it would work if I step into it but not when I call it from a cell?
ReplyDelete