The function returns the sum of the two numbers five (5) Step 4) Run the program, you will get the following results. Step 1: In the Developer Tab click on Visual Basic to open the VB Editor. Calling a Function from a Sub Procedure How to return multiple values from a VBA function (Part 1) Part 1: Using By Reference argument, collection, and dictionary object VBA functions (and other programming languages as well) can only return one value. Step 3: Now the function is declared, We need to declare a variable to store the position of the substring. First, we will use the ROW Function to tell us which row we are in:1=ROW(B3) . A sub procedure is not designed to return a value - that is what a function procedure is used for. Return Multiple Output Arguments from MATLAB Function. An example is calling the built-in Date function: Dim dtToday As Date dtToday = Date. Using reserved words can cause errors and unexpected results. [vbscript] how to return value from a function Can be called it from VBA\Button\Event etc. Example 1: excel how to return a result from a VBA function 'In VBA, you assign the return value to the name of the function. It calls the function addNumbers and passes in 2 and 3 as the parameters. You can also create functions that refer to objects in VBA but you need to use the Set Keyword to return the value from the function. VBA Return Values For example, you can pass two numbers in a function and then you can expect from the function to return their multiplication in your calling program. - Doug Jenkins Sep 13, 2018 at 23:18 Show 2 more comments 90 excel vba change font size for entire sheet VBA - User Defined Functions - Tutorials Point A return value of zero (0) indicates that the function ran successfully. Assign the return value the name of the function. The Smart View VBA functions return values indicating the success or failure of the function. Download Excel containing above code. Public sub test () x = 2 msgbox number (x) Exit Sub Public Function number (num) if len (num) = 1 then num = "0" + num End if End Function The function is returning a null value. It's a common and useful practice that we need to return more values from a function. Follow the below steps to use InStr function in VBA. The functions return several types of values: 0 (zero), the function was successful.