问题
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.
回答1:
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.
回答2:
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
回答3:
You can use the ^ operator to obtain square roots. Just raise the number you started with to the power of 0.5:
81^0.5 will give you 9 and 256^0.5 will give you 16
来源:https://stackoverflow.com/questions/43679570/square-root-function-in-vba-excel