The VBA Log Function

Related Function:
VBA Exp

Description

The VBA Log function returns the natural logarithm of a supplied number.

The syntax of the function is:

Log( Number )

Where the supplied Number is a positive numeric value that you want to calculate the natural logarithm of.


VBA Log Function Examples

The following VBA code shows three examples of the VBA Log function.

' Calculate the natural logarithm of three different values.
Dim val1 As Double
Dim val2 As Double
Dim val3 As Double
val1 = Log( 0.1 )
' The variable val1 is now equal to -2.30258509299405.
val2 = Log( 1 )
' The variable val2 is now equal to 0.
val3 = Log( 500 )
' The variable val3 is now equal to 6.21460809842219.

In the above VBA code:


VBA Log Function Errors

If the Number that is supplied to the Log function is less than or equal to 0, you will get the error:

Run-time error '5': Invalid procedure call or argument

VBA Run Time Error 5 Message Box


If the Log function is supplied with a value that cannot be interpreted as a number, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box