I have the following script in a Google Sheet Apps Script macro. It is meant to identify & delete a range of rows on a sheet. This was created by originally recording a macro & then attempting to edit the code.
The the first row in the range will always be the same (ie: row 34), but the last row in the range will vary. I have given a named range of "VestRows" to the last row.
I am using the code below to attempt to achieve the above, but it seems to fail on getting the range to activate (and then delete). If I use the named range (ie: VestRows) in replacement of the actual row number (ie: 40), it fails. But using the row number works as expected.
For example, in the code below if I replace
spreadsheet.getRange('34:vr').activate();
with
spreadsheet.getRange('34:40').activate();
it works. Any help would be much appreciated.
My Non-Working Macro:
function DelteRowsTest() {
var spreadsheet = SpreadsheetApp.getActive();
var vr = SpreadsheetApp.getActive().getRangeByName("VestRows");
spreadsheet.getRange('34:vr').activate();
spreadsheet.setCurrentCell(spreadsheet.getRange('A40'));
spreadsheet.getActiveSheet().deleteRows(spreadsheet.getActiveRange().getRow(), spreadsheet.getActiveRange().getNumRows());
};
The code below is working, but not what I am after:
function DelteRowsTest() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('34:40').activate();
spreadsheet.setCurrentCell(spreadsheet.getRange('A40'));
spreadsheet.getActiveSheet().deleteRows(spreadsheet.getActiveRange().getRow(), spreadsheet.getActiveRange().getNumRows());
};
'34:vr'
, what isvr
? Also please add a brief description of your search efforts as is suggested in How to Ask.