Select Page

Thomas Szigeti

## How to do square root in VBA?

A lot of you reached out with this question on how to do square root in Excel VBA.
It is a fairly simple formula. Even the VBA syntax is manageable.
Let`s jump in and see what we can do!

### To get to square root of a number in an Excel formula

We need to use the SQR function.
It can be found on the ribbon under the formulas tab.
You can find it in the Math/Trig formulas.

Syntax of the SQR function

For a formula you can use this syntax
=SQR(number)

The number you want to get the square root of must be positive.
If you put a negative number within the brackets it will throw an error.

Luckiy we can use the ABS formula to correct this. If you put =ABS(SQR(number)) then the possible negative number will get converted into the absolute value which will be positive.

``````Sub test

Dim myResult As Double

myResult = Sqr(300)

Msgbox myResult

End Sub``````

### Syntax for VBA

The syntax for VBA is pretty much the same as for the formula.

In the VBA editor you can put:

=Sqr(99)
The result will be: 33

You can see the proper use within a Subroutine on the left.

In this example  the Variant myResult will be written out in to a messagebox, and it will contain the result of 100.

## Delete named ranges with VBA code

Thomas Szigeti Another one of those issues that you come across when you are busy, and have to do things on the fly. When your manager sends you a file to adjust something. Then you open the file, and start to get the feeling that "something is not right here"...And...

## Export Range to jpg with Excel VBA

Sometimes we have to do silly stuff... No surprise my next sentence starts with: -At work...  At work I ran in to the task of having to deliver -repeatedly- a small table from one of our reports as a .jpg to be inserted in to a powerpoint presentation. I tried to...

## Automatically add button to worksheet in VBA with a macro assigned to it.

Recently I had to make a file where the challenge was to create an easy way for the user to remove any rows from the dataset. I know... Right click->Delete row. Trust me. It had to be a lot simpler than that.    So I created a macro that places a button in the...

## Square root VBA

Thomas SzigetiHow to do square root in VBA? A lot of you reached out with this question on how to do square root in Excel VBA.It is a fairly simple formula. Even the VBA syntax is manageable.Let`s jump in and see what we can do! To get to square root of a number in an...

## Delete Rows with VBA

Thomas SzigetiHey all! Today we will discuss a VBA technique which we have to use every now and again. This is when we have to delete row or rows in a workbook with VBA code.Deleting rows in VBA is a bit tricky because if you start looping through the rows and delete...

## Convert Conditional formatting

Have you ever had to convert conditional formatting on a sheet? It happened to me in more than one occasion.Usually when I had a nice sheet with all the bells and whistles, all conditional formatting working and colorful, then I...

## Excel VBA Clear the clipboard

How to clear the clipboard in my Excel VBA Code? Every now and again we need to clear the clipboard from our Excel VBA code. This can be for one or more reasons. The most common is that we pasted the content of the clipboard, and we need to free up the memory. This...

## How to add autosave with a piece of VBA code to any excel workbook?

Have you ever wished that you could add some kind of autosave to your workbook that you control?While the built in Autosave in MS Excel works most of the time,there are instances where you want to secure your work yourself. How can we do this? We will need to add two...

## How to add an Excel VBA code to my workbook?

I found an Excel VBA Code on the internet. How do I add it to my Excel file? O.K. So first I want to share a bit of information on What is VBA code.For the actual steps please scroll down.What is VBA Code in excel?VBA is stands for Visual Basic for Applications. It is...

## Remove Accents in text with a custom VBA function

Thomas SzigetiHi All. Today I will give you a solution to a problem that can affect some of my non English language users.I'm a native Hungarian and as such, our alphabet includes some funny letters with Hungarian accents on it. Like: ÁáÉéŰűÚúŐőÓóÜüÖö. They are...