 # VBA Log Function in Excel

VBA Log function in Excel is categorized as Math(Mathematical) & Trig function. This is a built-in Excel VBA Function. This function returns the natural logarithm of a specified number.

We can use this function in Excel and VBA. This function we use in either procedure or function any number of times in a Excel VBA editor window. Let us learn what is the syntax and parameters of the Log function. Let us see where we can use this Log Function and real-time examples in Excel VBA.

## Syntax of VBA Log Function

The syntax of the Log Function in VBA is

`Log(Number)`

The Log function returns a double value.

#### Parameters or Arguments:

The Log function has one argument in Excel VBA.
where
Number:The Number is a required parameter. This argument represents a number or numeric value, which consists double data type. The specified number should be positive number or greater than zero. If specified number is negative,then returns an error.

### Where we can apply or use VBA Log Function?

We can use this Log Function in VBA MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

### Example 1: Calculate the log/logarithm value of the number(1.5)

Here is a simple example of the VBA Abs function. This below example calculates the log/logarithm value of the number(1.5).

```'Calculate the log/logarithm value of the number(1.5)
Sub VBA_Log_Function_Ex1()

'Variable declaration
Dim iValue As Double
Dim dResult As Double

iValue = 1.5

dResult = Log(iValue)

MsgBox "The logarithm value of the number 1.5 is : " & dResult, vbInformation, "VBA Log Function"

End Sub
```

Output: Here is the screen shot of the first example output. ### Example 2: Calculate the log/logarithm value of the number(1)

Here is another example of the VBA Abs function. This below example calculates the log/logarithm value of the number(1).

```'Calculate the log/logarithm value of the number(1)
Sub VBA_Log_Function_Ex2()

'Variable declaration
Dim iValue As Double
Dim dResult As Double

iValue = 1

dResult = Log(iValue)

MsgBox "The logarithm value of the number 1 is : " & dResult, vbInformation, "VBA Log Function"

End Sub
```

Output: Here is the screen shot of the second example output. ### Example 3: Calculate the log/logarithm value of the number(‘4’)

Let us see one more example of the VBA Abs function. This below example calculates the log/logarithm value of the number(‘4’).

```'Calculate the log/logarithm value of the number('4')
Sub VBA_Log_Function_Ex3()

'Variable declaration
Dim iValue As String
Dim dResult As Double

iValue = "4"

dResult = Log(iValue)

MsgBox "The logarithm value of the number '4' is : " & dResult, vbInformation, "VBA Log Function"

End Sub
```

Output: Here is the screen shot of the third example output. ### Example 4: Calculate the log/logarithm value of the number(-10)

Here is a simple example of the VBA Abs function. This below example calculate the log/logarithm value of the number(-10).

```'Calculate the log/logarithm value of the number(-10)
Sub VBA_Log_Function_Ex4()

'Variable declaration
Dim iValue As Double
Dim dResult As Double

iValue = -10

dResult = Log(iValue)

MsgBox "The logarithm value of the number -10 is : " & dResult, vbInformation, "VBA Log Function"

End Sub
```

Output: Here is the screen shot of the third example output. #### Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

#### Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.