Ad space (banner)
Lesson 8 / 20

Function procedures (work that returns a value)

This lesson covers the Function procedure, which can return a value such as a calculated result.

It is defined as Function Name(args) As ReturnType ... Name = value ... End Function. Assigning to the function's own name is what makes that value the return value.

The sample code defines Function AddTax(price As Long) As Long and returns the amount with sales tax added.

A common early stumble is forgetting to assign the result to the function name. Without AddTax = price + ..., the return value stays empty (0).

In professional work, it is handy to gather repeated calculations — sales tax, discounts — into Function procedures.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VBA directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)