VBA Log Function

VBA Log Function

Overview of VBA Log Function:


VBA Log function 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, 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, 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.
VBA Log Function

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

Here is a simple 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.
VBA Log Function

Example 3: Calculate the log/logarithm value of the number(‘4’)

Here is a simple 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.
VBA Log Function

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.
Invalid Procedure or Call Argument

Instructions to use Macro Codes

Let us see the step by step instructions to use the VBA Log function in Excel VBA.

  • Open an Excel workbook.
  • Press Alt+F11 to open VBA Editor window.
  • Go to Insert menu and click on module from the available options.
  • Copy above specified macros to the VBA editor.
  • Select any procedure from above codes and click on ‘Run’ command or use Keyboard shortcut ‘F5’.

List of VBA Functions:

Please click on below link to go back to see all List of VBA Functions.

VBA Math(Mathematical) & Trig Functions List of VBA Functions

Leave a Comment

Your email address will not be published. Required fields are marked *