totn Excel Functions

MS Excel: How to use the SQR Function (VBA)

This Excel tutorial explains how to use the Excel SQR function with syntax and examples.

Description

The Microsoft Excel SQR function returns the square root of a number.

The SQR function is a built-in function in Excel that is categorized as a Math/Trig Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.

Syntax

The syntax for the SQR function in Microsoft Excel is:

Sqr( number )

Parameters or Arguments

number
A positive number that you wish to return the square root for.

Returns

The SQR function returns a numeric value.
If a negative number is entered in the number parameter, the SQR function will raise an error.

Applies To

  • Excel for Office 365, Excel 2019, Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • VBA function (VBA)

Example (as VBA Function)

The SQR function can only be used in VBA code in Microsoft Excel. If you need to calculate the square root within a worksheet formula, try the SQRT function.

Let's look at some Excel SQR function examples and explore how to use the SQR function in Excel VBA code:

=Sqr(25)
Result: 5

=Sqr(30)
Result: 5.47722557505166

=Sqr(2.5)
Result: 1.58113883008419

For example:

Dim LResult As Double

LResult = Sqr(900)

Msgbox LResult

In this example, the variable called LResult would now contain the value 30.