Excel VBA : How to debug a user defined function (UDF)

Best Online Course : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects & Case Studies
- Job Placement Assistance
- Get 20% off till July 14, 2017

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 -
Function grade(score As Single, score1 As Single) As String
         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
Temporary Sub Procedure -

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.

Excel Tutorials : 100 Excel Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

2 Responses to "Excel VBA : How to debug a user defined function (UDF)"

  1. Perfect and simple solution. Thanks. Gary

    ReplyDelete
  2. Thanks - this was helpful!

    ReplyDelete

Next → ← Prev