ByRef and ByVal

You can pass arguments to a procedure (function or sub) by reference or by value. By default, Excel VBA passes arguments by reference. As always, we will use an easy example to make things more clear. Place a command button on your worksheet and add the following code lines: Dim x As Integerx = 10 […]

Volatile Functions

By default, UDF’s (User Defined Functions) in Excel VBA are not volatile. They are only recalculated when any of the function’s arguments change. A volatile function will be recalculated whenever calculation occurs in any cells on the worksheet. Let’s take a look at an easy example to explain this a bit more. 1. Open the […]

Custom Average Function

Below we will look at a program in Excel VBA which creates a User Defined Function that calculates the average of a randomly selected range excluding one or more values that are outliers and shouldn’t be averaged. Situation: User defined functions need to be placed into a module. 1. Open the Visual Basic Editor and […]