Excel VBA Sqr Function
VBA Sqr Function: The Sqr function in VBA returns the square root for the specified number.
Syntax
Sqr (Number)
Parameter
Number (required) – This parameter represents a positive numeric value that you want to calculate the square root.
Return
This function returns the square root for the specified number.
Example 1
Sub SqrFunction_Example1() ' Finding the square root for the given numbers Dim sqr_val As Double sqr_val = Sqr(25) ' Now, the variable sqr_val will return 5 Cells(1, 1).Value = sqr_val End Sub
Output
5
Example 2
Sub SqrFunction_Example2() ' Finding the square root for the decimal numbers Dim sqr_val As Double sqr_val = Sqr(6.25) ' Now, the variable sqr_val will return 2.5 Cells(1, 1).Value = sqr_val End Sub
Output
2.5
Example 3
Sub SqrFunction_Example3() ' Finding the square root for the negative numbers Dim sqr_val As Double sqr_val = Sqr(-6.25) ' Now, the variable sqr_val will return run time invalid procedure error Cells(1, 1).Value = sqr_val End Sub
Output
Example 4
Sub SqrFunction_Example4() ' Finding the square root for 0 Dim sqr_val As Double sqr_val = Sqr(0) ' Now, the variable sqr_val will return 0 Cells(1, 1).Value = sqr_val End Sub
Output
0