Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square root function in VBA, Excel

Tags:

excel

vba

What is the square root function in VBA excel? I tried SQRT() and Root() but none of them are working, my Excel version in 2013.


2 Answers

Use the oddly named

VBA.Sqr(n)

where n is your number for which you want the square root computed. The VBA. prefix is optional, but it helps descriminate between VBA and any other library you might have referenced.

like image 124
Bathsheba Avatar answered Sep 04 '25 14:09

Bathsheba


Nth root can be obtained with VBA with:

Option Explicit

Function NthRoot(dblNumber As Double, lngRoot As Long) As Double
    NthRoot = dblNumber ^ (1 / lngRoot)
End Function

So for square root:

? NthRoot(64, 2)
 8 
? NthRoot(64.33333, 2)
 8.02080606921773 
like image 20
Robin Mackenzie Avatar answered Sep 04 '25 16:09

Robin Mackenzie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!