Excel VBA Log Function

VBA Log Function: The Log function in VBA returns the natural logarithm for the specified number.

Syntax

Log (Number)

Parameter

Number (required) –This parameter represents a positive numeric value that you want to find the natural logarithm of.

Return

This function returns the natural logarithm for the specified number.

Example 1

Sub LogFunction_Example1()
 ' Calculating the natural logarithm value.
 Dim log_val As Double
 log_val = Log(1)
 ' The variable log_val will return to 0.
 Cells(1, 1).Value = log_val
 End Sub 

Output

0

VBA Log Function

Example 2

Sub LogFunction_Example2()
 ' Calculating the natural logarithm value.
 Dim log_val As Double
 log_val = Log(900)
 ' The variable log_val will return to 6.80239476332431.
 Cells(1, 1).Value = log_val
 End Sub 

Output

6.80239476332431

VBA Log Function

Example 3

Sub LogFunction_Example3()
 ' Calculating the natural logarithm value.
 Dim log_val As Double
 log_val = Log(0.89)
 ' The variable log_val will return to -0.116533816255952.
 Cells(1, 1).Value = log_val
 End Sub 

Output

-0.116533816

VBA Log Function

Example 4

Sub LogFunction_Example4()
 ' Calculating the natural logarithm value.
 Dim log_val As Double
 'for negative number
 log_val = Log(-1)
 ' The variable log_val will return to 0.
 Cells(1, 1).Value = log_val
 End Sub 

Output

VBA Log Function