简体   繁体   中英

Copy a range and paste only rows with values into another sheet at the next blank row?

I'm trying to build off of what was solved here:

How do you copy a range and paste only rows with values into another sheet?

I want to do this with a bigger range (O1:X500 on the sheet named "RGDR") copying only the rows with values in them and then paste them in the new sheet ("ACTUALFUNC") in the next blank row.

The sheet is here: https://docs.google.com/spreadsheets/d/1vvXQxBGffwBAjbXKqx4N-ZFcX40wuV7gg9flb6STWtA/edit?usp=sharing

Below is the code I already tried. It only brings over the first column of data.

function copyRangeNoEmpties(){
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('RGDR');
  var copyToSheet=ss.getSheetByName('ACTUALFUNC');
  var copyFromRange=sh.getRange('O1:X500');
  var vA=copyFromRange.getValues();
  var oA=[];
  for(var i=0;i<vA.length;i++)
  {
    if(vA[i][0])
    {
      oA.push([vA[i][0]]);
    }
  }
  var copyToRange=copyToSheet.getRange(1,1,oA.length,1);
  copyToRange.setValues(oA);
}

Looking to build a ongoing list of results by running this once daily. Any help or input will be greatly appreciated.

This will append your data to the next row on your destination sheet.

function copyRangeNoEmpties(){
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('RGDR');
  var des=ss.getSheetByName('ACTUALFUNC');
  var src=sh.getRange('O1:X500');
  var vA=src.getValues();
  for(var i=0;i<vA.length;i++) {
    if(vA[i].join("")) {
      des.appendRow(vA[i]);
    }
  }
}

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