In this post I will show you how you can test a custom function in the immediate window. When you develop advanced VBA applications with multiple subroutines and functions you may need to test them while developing the code. Then you can use this technique to test individual functions without running the whole program. So now let’s look at how to call a user defined function from the immediate window. Here is a simple custom function I created to use as an example.
Dim a As Long
Dim b As Long
Dim c As Long
Dim Result As Long
a = 1000
b = 2000
c = 3500
Result = a + b + c
SumValues = Result
End Function
This is a very simple function which returns the sum of three values. Now let’s see how we can test this function in the immediate window. First open the immediate window if it is not already opened.
How to Show Immediate Window in VBA Environment
When you open the immediate window you can test the custom function using one of the below two methods.
Method 1
Enter the function name followed by a question mark.
So here is the result you will get.
That's one way to call a custom function from the immediate window.
Method 2
In this method we are going to use the debug.print method to print the result of the function in the immediate window.
This is how you can test a custom VBA function in the immediate window using this second method.
Also read
How to Return an Array From VBA Function
How to Pass an Array to a VBA Function
How to Search For Multiple Strings Using VBA InStr Function
BESSELJ Function