Square root function in VBA, Excel

穿精又带淫゛_ 提交于 2021-02-07 20:23:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!