Home > database >  Add Row before the selected cell
Add Row before the selected cell

Time:06-18

I would like to create a script where i can add row (in the previous row) where I select a cell.

For exemple, I have a tab of sheet with 50 rows. If i select the 32th row and launch my script, i would like to add a new row in this 32th row and, finally, have 51 rows in my tab.

After researchs in web, i don't find anything about that. It's possible i don't know how to search because i'm french and probably i used bad words for that.

This is the beginning of my code but it's don't work ...

function ajoutLigne(e) {
   const classeur = SpreadsheetApp.getActiveSpreadsheet();
   const feuille = classeur.getActiveSheet();
   const ui = SpreadsheetApp.getUi();

   var rowIndex = feuille.getRange(e).index();
   Logger.log(rowIndex);
 }

Thank you for advance to your help

CodePudding user response:

Try:

function insertRow() {

  const sheet = SpreadsheetApp.getActiveSheet()
  const index = sheet.getActiveRange().getRow()
  
  sheet.insertRowBefore(index)

}

This will get the index of the active row, and insert a blank row.

  • Related