copy a range, paste and clear some data from particular cells

1,283 views
Skip to first unread message

Picloan Limited

unread,
Apr 2, 2022, 7:03:55 AM4/2/22
to Google Apps Script Community
Dear sir, please help me. I am trying to copy some range from L4 TO P20 AND PASTE TO another sheet and also clear B7,C4  and G7 on List sheet. But my script  copy only one row and B7,C4 and G7 were not clear. Please help me.

function moveValuesOnly() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getRange("List!L4:P20");
var destSheet = ss.getSheetByName("Sheet6");
destSheet.appendRow(source.getValues()[3]);
Source.getRange('B7,C4,G7').clearContent()
  }

Tanaike

unread,
Apr 2, 2022, 11:46:11 PM4/2/22
to Google Apps Script Community
I believe your goal is as follows.

  • You want to copy the values from "List!L4:P20" to "Sheet6".
  • You want to clear the cells "B7,C4,G7" of "List" sheet after the values were copied.

Modification points:
  • About "destSheet.appendRow(source.getValues()[3]);", "appendRow" appends a row to the sheet. In this case, I thought that `copyTo` can be used.
  • "Source" is not defined in your script.
  • In order to clear the cells of  "B7,C4,G7", I think that RangeList can be used.

When these points are reflected in your script, it becomes as follows.

function moveValuesOnly() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getRange("List!L4:P20");
  var destSheet = ss.getSheetByName("Sheet6");
  source.copyTo(destSheet.getRange(destSheet.getLastRow() + 1, 1), { contentsOnly: true });
  source.getSheet().getRangeList(['B7', 'C4', 'G7']).clearContent();
}


If this modified script was not useful, I apologize.

Picloan Limited

unread,
Apr 13, 2022, 7:33:16 AM4/13/22
to Google Apps Script Community
Very useful, I am very grateful you were reading  my mind.that was exactly what I wanted.God bless

Picloan Limited

unread,
Apr 13, 2022, 7:39:15 AM4/13/22
to Google Apps Script Community
Dear thank for solving that problem, what if I want to copy to another  worksheet . Like the one below. It just says the sheet must be in the same workbook sheet. Thanks in advance

function moveValuesOnly() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getRange("Listr!L4:p20");  
  var destSheet = SpreadsheetApp.openById("144K7R-h162rMKesKyxvxsAkRd4CmxXMRxE3hnphSZoA");
  let shtOut = destSheet.getSheetByName("Sheet6");



  source.copyTo(destSheet.getRange(destSheet.getLastRow() + 1, 1), { contentsOnly: true });
  source.getSheet().getRangeList(['B7', 'C4', 'G7']).clearContent();
}
Reply all
Reply to author
Forward
0 new messages