User`s guide

When to Use a Formula Function or a Subroutine
3-3
When to Use a Formula Function or a Subroutine
Visual Basic for Applications (VBA) provides two basic procedure types,
functions and subroutines. You access a VBA function directly from a cell in a
worksheet as a formula function and access a subroutine as a general macro.
Function procedures are useful when the original MATLAB function takes one
or more inputs and returns one scalar output. When the original MATLAB
function returns an array of values or multiple outputs, you need a subroutine
procedure to map these outputs into multiple cells/ranges in the worksheet.
When you create a MATLAB Excel Builder component, you produce a VBA
module (
.bas file). This file contains simple call wrappers, each implemented
as a function procedure for each method of the class.