VBA EXP Function in Excel (5 Examples)

VBA Exp function is a built-in function in Excel, categorized under the Math and Trig function. In this article, we will show you what Exp function in VBA is and how to use it with examples.


Introduction to the EXP Function in VBA

The Exp function in VBA returns a double value of the exponential function ex (mathematical constant e, the base of natural logarithms) raised to a supplied power for the given value of x.

  • Syntax

Exp(number)

  • Argument
Argument Required/ Optional Description
number Required The power – double or any valid numeric expression – to raise the constant e to.
  • Return Value

A double numeric value.


5 Examples of VBA EXP Function in Excel

In this section, we will show you how to use the Exp function in VBA with 5 easy examples.

1. Find the Exponential Value of -5 with VBA in Excel

Steps to find the exponential value of -5 with VBA are given below.

Steps:

  • Press Alt + F11 on your keyboard or go to the tab Developer -> Visual Basic to open Visual Basic Editor.

  • In the pop-up code window, from the menu bar, click Insert -> Module.

  • Copy the following code and paste it into the code window.
'Find the Exponential value of -5
Sub ExpOfMinusFive()
    'Variable declaration
    Dim iVal As Integer
    Dim iResult As Double
    iVal = -5
    iResult = Exp(iVal)
    MsgBox "The Exponential value of -5 is : " & iResult
End Sub

Your code is now ready to run.

VBA EXP for -5

  • Press F5 on your keyboard or from the menu bar select Run -> Run Sub/UserForm. You can also just click on the small Play icon in the sub-menu bar to run the macro.

You will get the exponential value of -5 in the Microsoft Excel message box.

EXP for -5 in VBA

Read More: How to Use VBA IsNumeric Function


2. Determine the Exponential Value of -0.3 with VBA EXP Function

Steps to find the exponential value of -0.3 with VBA are given below.

Steps:

  • Same way as before, open Visual Basic Editor from the Developer tab and Insert a Module in the code window.
  • In the code window, copy the following code and paste it.
'Find the Exponential value of -0.3
Sub ExpOfMinusZeroPointThree()
    'Variable declaration
    Dim iVal As Integer
    Dim iResult As Double
    iVal = -0.3
    iResult = Exp(iVal)
    MsgBox "The Exponential value of -0.3 is : " & iResult
End Sub

Your code is now ready to run.

VBA EXP for -0.3

  • Run this code and you will get the exponential value of -0.3 in the Excel message box.

EXP for -0.3 in VBA

Read More: How to Use VBA Val Function in Excel


3. Check the Exponential Value of 0 with VBA EXP Function

Steps to find the exponential value of 0 with VBA are given below.

Steps:

  • Previously shown, open Visual Basic Editor from the Developer tab and Insert a Module in the code window.
  • In the code window, copy the following code and paste it.
'Find the Exponential value of 0
Sub ExpOfZero()
    'Variable declaration
    Dim iVal As Integer
    Dim iResult As Double
    iVal = 0
    iResult = Exp(iVal)
    MsgBox "The Exponential value of 0 is : " & iResult
End Sub

Your code is now ready to run.

VBA EXP for 0

  • Run this code and you will get the exponential value of 0 in the Excel message box.

EXP for 0 in VBA

Read More: How to Use Fix Function in Excel VBA


4. Compute the Exponential Value of 0.1 from a Cell in Excel

To compute the exponential value of 0.1, we will store the value in a cell first then run the VBA code this time.

Notice in the above example, where we stored the value 0.1 in Cell B5. We will extract the exponential value of 0.1 in Cell C5.

Steps:

  • Open Visual Basic Editor from the Developer tab and Insert a Module in the code window.
  • In the code window, copy the following code and paste it.
Sub ExpOfZeroPointOne()
    Range("C5").Value = Exp(Range("B5"))
End Sub

Your code is now ready to run.

VBA EXP for a single cell

  • Run this code and you will get the exponential value of 0.1 in Cell C5.

VBA EXP for 0.1

Read More: Excel Formula to Generate Random Number


5. Calculate the Exponential Value of a Range of Cells with VBA in Excel

By following the code shown in the previous point, you can calculate the exponential value for a range of cells in Excel.

We will calculate the exponential value for the numbers shown in the picture above with the VBA code. You can store any numeric value in your dataset according to your need.

Steps:

  • Open Visual Basic Editor from the Developer tab and Insert a Module in the code window.
  • In the code window, copy the following code and paste it.
Sub ExpValueVBA()
    Range("C5").Value = Exp(Range("B5"))
    Range("C6").Value = Exp(Range("B6"))
    Range("C7").Value = Exp(Range("B7"))
    Range("C8").Value = Exp(Range("B8"))
    Range("C9").Value = Exp(Range("B9"))
    Range("C10").Value = Exp(Range("B10"))
End Sub

Your code is now ready to run.

VBA EXP value for a range of cell

  • Run this code and you will get the exponential value of all the numbers stored in the cells of the dataset in the cells mentioned in the code.

VBA EXP for a range of cell

Read More: How to Remove Scientific Notation in Excel


Things to Remember

  • The value of constant e is approximately 2.718282
  • If the value of the argument number exceeds 709.782712893, VBA will return a run-time 6 error.
  • If the value of the argument number is an unrecognized number or string, then VBA will throw a run-time 13 error.
  • This function integrates the action of the LOG function and is sometimes assigned to as the anti-logarithm.
  • The LOG function can be used to return the natural logarithm of a number.

Download Workbook

You can download the free practice Excel workbook from here.


Conclusion

This article showed you how to use the VBA Exp function in Excel. I hope this article has been very beneficial to you. Feel free to ask if you have any questions regarding the topic.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Sanjida Ahmed
Sanjida Ahmed

Sanjida Ahmed, who graduated from Daffodil International University with a degree in Software Engineering, has worked with SOFTEKO since 2021. She has written over 100 articles on Excel & VBA and, since 2022, has worked as the Project Manager of the Excel Extension Development Project in the Software Development Department. Since starting this software development, she has established an outstanding workflow encompassing a full SDLC. She always tries to create a bridge between her skills and interests in... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo