The VBA SQR Function


The VBA Sqr function returns the square root of a supplied number.

The syntax of the function is:

Sqr( Number )

Where the Number argument is a positive real number that you want the square root of.

VBA Sqr Function Examples

' Find the square root of the numbers 6.25 and 0
Dim res1 As Double
Dim res2 As Double
res1 = Sqr( 6.25 )
res2 = Sqr( 0 )
' Now, res1 = 2.5 and res2 = 0

In the above VBA code:

VBA Sqr Function Errors

If you supply a negative Number argument to the VBA Sqr function, you will get the error:

Run-time error '5': Invalid procedure call or argument

VBA Run Time Error 5 Message Box

If the Sqr function is supplied with a value that cannot be interpreted as a number, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box