totn Excel Functions

MS Excel: How to use the LOG Function (VBA)

This Excel tutorial explains how to use the Excel LOG function with syntax and examples.

Description

The Microsoft Excel LOG function returns the natural logarithm (base e) of a number.

The LOG function is a built-in function in Excel that is categorized as a Math/Trig Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.

Please read our LOG function (WS) page if you are looking for the worksheet version of the LOG function as it has a very different syntax.

Syntax

The syntax for the Microsoft Excel LOG function in VBA code is:

Log( number )

Parameters or Arguments

number
A numeric value that must be greater than 0.

Returns

The LOG function returns a numeric value.

Applies To

  • Excel for Office 365, Excel 2019, Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • VBA function (VBA)

Example (as VBA Function)

The LOG function can be used in VBA code in Microsoft Excel.

Let's look at some Excel LOG function examples and explore how to use the LOG function in Excel VBA code:

=Log(20)
Result: 2.995732274

=Log(25)
Result: 3.218875825

=Log(100)
Result: 4.605170186

=Log(7.5)
Result: 2.014903021

=Log(200)
Result: 2.301029996

For example:

Dim LResult As Double

LResult = Log(20)

In this example, the variable called LResult would now contain the value 2.995732274.