Script Lab in Excel

Last Updated: April 20, 2024
puneet-gogia-excel-champs

- Written by Puneet

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.

script-lab-in-excel

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.

add-script-lab-on-ribbon

Return to your worksheet and click the “Code” button from the Script Lab Tab.

click-code-from-script-lab-tab

When you click the code button, you will see a Pane on the right side of the Excel window.

pane-on-the-right-side

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.

with-script-lab-use-javascript-to-write-codes

Next, delete the code already there in all three tabs, Script, HTML, and CSS.

delete-the-codes-already-there

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.

register-function-with-excel-application

When you click the Register Button, it shows “The following functions have been registered successfully”.

shows-functions-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.

enter-a-number-in-cell

In the end, hit enter to get the result.

hit-enter-to-get-result