0

I am trying use google script delete Row 1500 until last row

    function DeleteR() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sn = ss.getSheetByName("xxx");
  if( sn.getLastRow() > 1500 ) {
    sn.deleteRows(1500,sn.getLastRow()-1500+1);
  }
  var sn2 = ss.getSheetByName("xxx2");
  if( sn2.getLastRow() > 1500 ) {
    sn2.deleteRows(1500,sn2.getLastRow()-1500+1);
  }
  var sn3 = ss.getSheetByName("xxx3");
  if( sn3.getLastRow() > 1500 ) {
    sn3.deleteRows(1500,sn3.getLastRow()-1500+1);
  }
}

1 Answer 1

2

Description

Use Sheet.deleteRows(rowPosition, howMany)

Script

function DeleteR() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sn = ss.getSheetByName("xxx");
  if( sn.getLastRow() > 1500 ) {
    sn.deleteRows(1500,sn.getLastRow()-1500+1);
  }
}

Reference

Sign up to request clarification or add additional context in comments.

6 Comments

Hi TheWizEd thx your answer,this is my new script but still wont work you know what's wrong
Pho, don't post it as an answer. Edit your original post. And all I can say is are you sure there are more than 1500 rows? And does the execution log show any errors?
Yes i am sure more than 1500 rows,notice is showing Execution completed but i check back 3 sheet nothing has changed
Sorry maybe it should be if( sn.getLastRow() >= 1500 ) {? How many rows are there?
I have found the problem because I have a lot of empty rows in my data
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.