简体   繁体   中英

Modify Code - Copy Certain Rows/Columns From one Spreadsheet to Another - Google Apps Script / Google Sheets

I would like to incorporate the action the SORT QUERY is doing (above .getRange line of code) in this script. So instead of copying A2:FI would get Column B, C, D, E copied from ONLINESendNewSkusToGID to RECTOONLINE.

function CopyNewOnlineSkusFromCDSToGID() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('ONLINESendNewSkusToGID'), true);

  //=SORT(QUERY(JIRA JQL QUERY!A2:F,"SELECT B, C, D, E",0))
  spreadsheet.getRange('A2:F').activate();

  var target = SpreadsheetApp.openById("");
  var source_sheet = spreadsheet.getSheetByName("ONLINESendNewSkusToGID");
  var target_sheet = target.getSheetByName("RECTOONLINE");

  var source_range = source_sheet.getActiveRange();
  var last_row = target_sheet.getLastRow();
  var values = source_range.getValues();
  target_sheet.getRange(last_row + 1, 1, values.length, values[0].length).setValues(values);
  spreadsheet.getRange('A2').activate();
}

Thanks In Advance

Solution

Here is the code snippet that copies the columns B to E from one sheet to other. Let me know if this is what you meant to achieve with your question.

 function CopyNewOnlineSkusFromCDSToGID() { // get spreadsheet var ss = SpreadsheetApp.getActiveSpreadsheet(); // get the two desired sheets var online = ss.getSheetByName("ONLINESendNewSkusToGID"); var rect = ss.getSheetByName("RECTOONLINE"); // get the values of the sheet we want to copy var values = online.getRange('B:E').getValues(); // set the values where we want to paste rect.getRange('B:E').setValues(values); }

For more info regarding how to get and set values check out here and here respectively. I hope this has helped you, let me know if you need anything else or if you did not understood something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM