In VBA there are Subs and Functions. The main difference between the two is that the Function can return a value, where the Sub can’t.

If there is a requirement for Excel VBA to perform a task that returns a result, you can use a function. A Function can be created in the same way as a Sub.

Function example:

Function Area(x As Double, y As Double) As Double

	Area = x * y

End Function

The function can be reffered by simply using the name of the function and giving a value for each argument.

z = Area(3, 5) + 2

Categorized in:

VBA Excel,

Last Update: May 18, 2024