Insert Rows with an Office Script in Excel for the Web
Question details
The user wants to insert a row at a selected location in Excel for the web using a script and an optional button.

- Product
- Microsoft Excel for the web
- Device & OS
- not provided
- Scenario
- A workbook user selects a cell and runs a script to insert a row above it.
- Observed behavior
- Excel for the web does not run VBA macros, so an Office Script can provide the row-insertion action instead.
Open the workbook in Excel for the web and check that the Automate tab is available. Office Scripts availability depends on your Microsoft 365 account and organization settings.
Create an Office Script to Insert a Row Above the Active Cell
Use this script when workbook users need to insert a row at the active cell without running VBA.
In Excel for the web, open the workbook, select the Automate tab, and choose New Script.
Replace the editor contents with: function main(workbook: ExcelScript.Workbook) { const selectedCell = workbook.getActiveCell(); selectedCell.getEntireRow().insert(ExcelScript.InsertShiftDirection.down); }
Save the script with a descriptive name. Select a cell in the row where you want the new row inserted, then select Run in the script editor. A new row appears above the active cell.
Open the saved script from Automate, then use its More options menu to choose Add button to worksheet. Users can select a cell and click the button to run the script.

Edit Excel Workbooks with WPS Spreadsheet
WPS Office is a free, lightweight Office alternative with a familiar interface and Excel format compatibility for an easy transition. Use WPS Spreadsheet for everyday workbook editing; it does not replace this Excel Office Script or fix Excel for the web.

Frequently Asked Questions
Where does the Office Script insert the new row?
It inserts a row above the active cell. Select a cell in the target row before running the script or clicking its worksheet button.
Why can't I find the Automate tab?
Office Scripts availability depends on your Microsoft 365 account and organization settings. Check that you are signed in with an eligible account, or ask your administrator whether Office Scripts are enabled.
Can I run a VBA macro instead in Excel for the web?
No. Excel for the web cannot run VBA macros. Use an Office Script for this row-insertion task, or open the workbook in a desktop version of Excel to run supported VBA macros.
Can colleagues use the script button?
They can use it if they have the necessary access to the workbook and Office Scripts. Add the button from the saved script's More options menu in the Automate tab.




