Forum Discussion
James_Furmage
Sep 11, 2022Copper Contributor
Excel online script for adding multiple new rows
Hello everyone, I'm wondering if there is a way to create a Script that will add one or more rows at the users desired location? I know this is a very simple thing to do in excel anyway but this migh...
EdwardJ-RITS
Jun 18, 2024Copper Contributor
Thanks for this mate, this is what I was after looked high and low looking all over the internet.
Just wondering if there is a way that from what you have said you can also able to copy the first column in that row to the row that you are freshly inserting?
Cheers
MichelleRanMSFT
Microsoft
Jun 21, 2024EdwardJ-RITS this script should insert a new row under the selected cell and copy the value from the first column:
function main(workbook: ExcelScript.Workbook) {
let selectedRow = workbook.getActiveCell().getEntireRow();
let newRow = selectedRow.getEntireRow().insert(ExcelScript.InsertShiftDirection.down);
newRow.getCell(0, 0).setValue(selectedRow.getCell(0, 0).getValue());
}
Let me know if that helps, or if you have any questions!