The VBA Log function returns the natural logarithm of a supplied number.
The syntax of the function is:
Where the supplied Number is a positive numeric value that you want to calculate the natural logarithm of.
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 )
val3 = Log( 500 )' The variable val2 is now equal to 0. ' The variable val3 is now equal to 6.21460809842219. |
In the above VBA code:
If the Number that is supplied to the Log function is less than or equal to 0, you will get the error:
If the Log function is supplied with a value that cannot be interpreted as a number, it will return the error: