With Script Lab, you can use the Office JavaScript API. To get the “Script Lab”, you must install the script lab add-in from Insert Tab ⇢ Get Add-Ins ⇢ Script Lab.
The next thing you need to do is to add the Script Lab tab on the ribbon. And for this, go to the File Tab ⇢ Options ⇢ Customize Ribbon ⇢ Tick Mark ⇢ Script Lab.
Return to your worksheet and click the “Code” button from the Script Lab Tab.
When you click the code button, you will see a Pane on the right side of the Excel window.
With Script Lab, you can use JavaScript to write codes and create a custom function within Excel. Now, click the menu button and then the New Button.
Next, delete the code already there in all three tabs, Script, HTML, and CSS.
When you paste the code, the HTML and CSS tab will disappear because this code creates a function. And this function helps you to calculate the SQUARE OF A NUMBER.
/** * calculates the square root of the number.
* @customfunction
*/
function getsquare(num) {
return Math.pow(num, 2);
}
From here, you need to register this function within your Excel Application. First, click on the “Register” button.
When you click the Register Button, it shows “The following functions have been registered successfully”.
Now come back to the worksheet and enter a number in a cell. For example, enter “=ScriptLab” in another cell and select the GETSQUARE function. Refer to the cell with the number.
In the end, hit enter to get the result.