VBA LOG Function

HomeVBA Functions LIST (Category Wise)How to use the VBA LOG Function (Syntax + Example)

What is VBA LOG Function

The VBA LOG function is listed under the math category of VBA functions. When you use it in a VBA code, it returns the logarithm of the number you supplied. The logarithm is a mathematical calculation that is the inverse function of exponentiation. You can learn more about this calculation from here.

how to use it

To use VBA's LOG function you need to understand its syntax and arguments:

Syntax

Log(Number)

Arguments

  • Number: The number for which you want to calculate the natural logarithm.

Example to use LOG Function in VBA

To practically understand how to use VBA LOG function, you need to go through the below example where we have written a vba code by using it:

Sub example_LOG()
Range("B1").Value = Log(Range("A1"))
End Sub

In the above code, we have used the LOG to get the natural logarithm of the number we have in the cell A1 and it has returned 2.70805020110221 in the cell B1 as a result.

Notes

Below are some important points which you need to take care while using LOG function in VBA.

  • If the supplied number is less than or equals to 0 then VBA will return a run-time 5 error.
  • If the value specified is a value other than a number or a number that can't be recognized as a number, VBA will return the run-time 13 error.

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.