VBA LOG Function (Syntax + Example)


- by Puneet

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 here.




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


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

Sub example_FILTER()
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 cell A1 and it has returned 2.70805020110221 in cell B1 as a result.


  • If the supplied number is less than or equals 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.