D
D
Daniil Secrets2021-10-25 20:47:26
Google Apps Script
Daniil Secrets, 2021-10-25 20:47:26

How to find the starting position for deleting selected rows?

Good evening! I need to delete the selected row, but I don't know how to find the first parameter (row number) in the deleteRows method. Please help me who understands!

function myFunction() {

var sheetActive = SpreadsheetApp.openById("18TC8ShpPeMr5NcIwahUIl58wQIIt8qeECcM21ECMGIE");
var sheet = sheetActive.getSheetByName("ДАННЫЕ");

// The code below logs the background active_Range for the active range.
var active_Range = SpreadsheetApp.getActive().getActiveRange();

let active_RangeValues = active_Range.getValues();

active_RangeValues.forEach(function(item){
  sheet.appendRow(item)
})

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Лист1");
// Rows start at "1" - this deletes the first two rows
sheet.deleteRows(1, active_RangeValues.length);

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2021-10-25
@DannYLook

let row = SpreadsheetApp.getActiveRange().getRow();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question