How To Return A Result From A Function In VBA

Опубликовано: 22 Апрель 2026
на канале: Ctrl-Shift-Run
1,095
7

In this video, we look at how to return a result from a function in VBA. If you're familiar with other programming languages like Java, you will be familiar with the return statement.

The return statement returns a value from the method and exits the function. VBA does not have a return statement. Instead, the name of the function is treated like a variable name which you can assign values to.

For example, if you have a function called area(), you can assign the value of area like so:

area = 6

If the function returns an object like a Range, you will need to use the 'Set' keyword like so:

Set r = test()

Timestamp:
0:54 - Function that returns a Long value
3:32 - Assigning return value multiple times and exiting function
6:08 - Using the Set keyword for functions which return an object