You must provide values for all arguments that aren’t optional. But if there are no arguments, you can omit the parentheses or just leave them blank (). [2] X Research source When you call a function, its statements run beginning with the first executable statement after the Function statement until End Function, Return, or Exit Function is encountered. [3] X Research source Unlike when calling a subroutine, you usually won’t need to include the Call keyword when calling a function. [4] X Research source If you use the Call keyword, no value will be returned. If you’re using VBA in a cell within an Excel spreadsheet, the syntax is =functionName(argument1, argument2). If you’re writing code in the Excel VB editor, you’ll use the standard syntax. But in a cell, you’ll need to preface the call with an equals sign as you would when writing a formula.

First, let’s create the function. Function hypotenuse(ByVal side1 As Single, ByVal side2 As Single) As Single Return Math. Sqrt((side1 ^ 2) + (side2 ^ 2)) End Function And here’s how we’d call the function if one side is 2. 3. Dim testLength, testHypotenuse As Single testHypotenuse = hypotenuse(testLength, 2. 3)

First, here’s the function: Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Dim Res as integer Res = x + y Add = Res End Function Now, let’s call the function in a subroutine to add our numbers: Sub Form_Load() Dim a As Integer Dim b As Integer Dim c As Integer a = 32 b = 64 c = Add(a, b) MsgBox (“Sum is : " & c) End Sub