1

I have some items recorded

My spreadsheet

How to programmatically clear all the lines, starting from the second line, i mean except from the bold titles (NAME,BARCODE,QUANTITY,PRICE)?

This is my goal

And this is what i have done. How to continue?

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
range = sheet.getRange("A"+num+":D"+num+"");

2 Answers 2

2

player019, try this:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
range = sheet.getRange("A2:D");
range.clearContent();
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the method getMaxRows() and getMaxColumns() to get the last row and col. So, you may want to try:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var startRow = 2;
var startCol = 1;
var range = sheet.getRange(startRow, startCol, sheet.getMaxRows(), sheet.getMaxColumns());
sheet.setActiveRange(range);
range.clearContent();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.