Return to VBA Code Examples

VBA Log Function

Log Description

Returns the natural logarithm of a number.

Simple Log Examples

This code will return 4.60517018598809

Log Syntax

In the VBA Editor, you can type  “Log(” to see the syntax for the Log Function:

The Log function contains an argument:

Number: Any valid numeric expression greater than zero.

Examples of Excel VBA Log Function

Result: 2.30258509299405

Result: 3.46573590279973

All the above examples are cases with the base e(the base of the natural logarithm).

To calculate the logarithm with any base, you can use the code as following function.

The result will be as following.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!