Are you looking for a way to square a number?
If you work in a field like carpentry, engineering, architecture, or technology, you probably are!
Squaring a number is the mathematical operation of multiplying a number by itself. As an example, a square-sized bedroom measuring 10 feet wide and 10 feet long could be expressed as 100 square feet by multiplying 10 by 10.
This post explores all the different ways to square a number in Microsoft Excel.
Square a Number with the Multiplication Operator
The most straightforward way to square a number is to multiply it by itself using the traditional multiplication operator.
= B3 * B3
The above formula will multiply the number in cell B3 by itself. The asterisk (*
) is the operator for multiplication.
You’ve just squared your number from cell B3!
To apply your formula to your other numbers, hover over the lower-right corner of the formula’s cell until your cursor turns to a plus (+), then double-click.
Square a Number with the Carat Operator
The carat operator (^
) in Excel is designed for the specific operation of raising a number to a given power such as a square.
= B3 ^ 2
To implement the carat operator on your number in cell B3, select an empty cell and paste the above formula into the formula bar.
The above value 2
following the carat operator is called the exponent of your number. Specifying 2 as your exponent will square the number.
Your number has been squared!
Hover the cursor over the active cell fill handle and double-click to fill the formula down.
Square a Number with the POWER Function
The POWER function is an expert way to calculate a number involving an exponent.
= POWER( B3 , 2 )
To square your number from cell B3 using the POWER function, select an empty cell and paste the above formula into the formula bar.
The second argument is 2
. This is the exponent of your number, so always specify 2
here for squaring.
Press Enter when done and see how your number gets squared!
To apply your formula to your other numbers, hover over the lower-right corner of the formula’s cell until your cursor turns to a plus (+), then double-click.
Square a Number with the PRODUCT Function
The PRODUCT function provides general multiplication of values in Excel. Because squaring is just a specific case of multiplication, you can use PRODUCT to square your number.
= PRODUCT( B3 , B3 )
To use PRODUCT against your number in cell B3, select an empty cell and paste the above formula into the formula bar.
Your cell B3 is specified twice in the above formula because you’d like to multiply the B3 number by itself.
Press Enter to calculate the square of your number!
Double-click on the active cell fill handle to copy and paste the formula down your column.
Square a Number with the SUMSQ Function
Though the SUMSQ function is generally used for the summation of squared numbers, its summation feature is optional, leaving you the ability to simply square a single number.
= SUMSQ( B3 )
To leverage SUMSQ for a number in cell B3, select an empty cell and paste the above formula into the formula bar.
You only need to provide your value from the cell B3
and SUMSQ will square it.
Press Enter and behold your squared number!
Double-click on the fill handle to copy down the formula.
Square a Number with Paste Special
Excel has a paste special feature that allows you to multiply copied numbers.
To square numbers using this feature, you copy your numbers to the clipboard, then paste over it with an instruction to multiply it by the clipboard contents.
Here’s how it works for a range of numbers.
- Select your range of numbers.
- Copy your numbers to the clipboard by selecting Copy under the Home ribbon tab or press Ctrl + C.
- While your number range is still selected, go to the Home ribbon tab, drop down the Paste menu and select Paste Special.
Alternatively, you can simply press Ctrl + Alt + V.
This will open the Paste Special menu.
- Select Multiple from the Paste Special dialog.
- Click on the OK button.
Each number in your selected range has now been squared!
Square a Number with Power Query
Power Query is a powerful data transformation tool for Excel table data.
Once your numbers are arranged in a table, you can create a query that dynamically squares your numbers by using a Power Query formula.
Follow these steps to get started.
- Select your range of numbers, including the column header.
- Select From Table/Range under the Data ribbon tab.
- At the Create Table prompt, click OK to convert your range into a table.
- Go to the Transform ribbon tab in the Power Query Editor.
- Click on the Scientific menu in the Numbers Column.
- Select the Power submenu.
- Select the Square option.
Your numbers have now been squared!
You can then place the squared numbers on your sheet.
- Under the Home ribbon tab, drop down the Close & Load menu and select Close & Load To.
- Choose a destination for your results. For example, choose the Existing worksheet starting at cell D2.
- Click OK.
Now your squared numbers appear as a range alongside your original numbers!
Square a Number with VBA
VBA is the code responsible for automating tasks in Excel.
If you’d like to square numbers in a range based on what is currently selected, VBA would be a good way to do that.
Here’s how to explore this option.
- First ensure that you see the Developer ribbon tab, since it may be hidden by default.
- Go to the Developer ribbon tab.
- Click Visual Basic or simply press Alt + F11.
- From the Visual Basic editor select the Insert menu.
- Select the Module menu item.
Sub SquareNumbers()
Dim selectedRange As Range
Set selectedRange = Application.Selection
For Each cell In selectedRange.Cells
If Len(cell.Value) > 0 Then
cell.Value = cell.Value * cell.Value
End If
Next cell
End Sub
- In the new module window, paste the above VBA code.
The code will retrieve each cell
in the currently-selected range selectedRange
.
The cell’s value will get updated to a multiple of itself, effectively squaring the number. The Len()
function is used to skip blank cells to which squaring does not apply.
- To run your code, go back to your sheet and select your range of numbers.
- Under the View ribbon tab, select Macros.
- Select your SquareNumbers macro.
- Click the Run button.
Tada! Your numbers have been squared in place!
Square a Number with Office Scripts
Office Scripts is the latest automation language available in Excel for the web if you have a Microsoft 365 business plan.
With Office Scripts, you can create a reusable script to automate the squaring of your numbers in a selected range.
Follow these steps to start your script.
- Go to your browser and open your workbook in Excel for the web.
- Go to the Automate ribbon tab.
- Select the New Script option.
function main(workbook: ExcelScript.Workbook) {
let range = workbook.getSelectedRange();
let rowCount = range.getRowCount();
let colCount = range.getColumnCount();
for (let row = 0; row < rowCount; row++) {
for (let col = 0; col < colCount; col++) {
let currCell = range.getCell(row, col);
let currValue = currCell.getValue();
if (currValue.toString().length > 0) {
currCell.setValue(currValue * currValue);
};
};
};
}
- Paste the above script in the Code Editor pane.
The script gets the currently-selected range and loops through each cell.
The cell’s value gets updated to a multiple of itself. This squares the number before moving to the next cell.
This avoids updating blank cells by checking the length of the cell value before multiplying the value.
- Save your script by clicking the Save script button.
You can then run your script.
- Select your desired range of numbers.
- Click the Run button in the Code Editor pane.
The script has now replaced all your selected numbers with their squares!
Conclusions
In this post, you’ve seen many different options to square a number in Excel.
For a workbook whose calculations need to be easily understood, a traditional multiplication operator is a good option. Whereas the carat operator can offer a more concise formula.
The POWER, PRODUCT, or SUMSQ functions will get the job done and integrate better into a workbook that takes advantage of its unique design features.
The paste special option is an interesting way to square numbers in place on your sheet.
The Power Query option could be useful to square numbers as part of a larger workbook data transformation.
Finally, for a fully automated solution that reacts to changing range selections, VBA or Office Scripts is a good option. The choice will generally depend on which Excel app you’re using. Office Scripts is best for the web, while VBA is a good desktop alternative.
Which method do you use when you need to perform square calculations? Let me know in the comments!
0 Comments