Skip to content Skip to sidebar Skip to footer

Moving Filtered Values (copy And Paste Values) Using Google Sheet Script While Ignoring The Column Heading / Title

I would like to copy and paste VALUES only from source sheet to target sheet using google scripts. I have filter applied in the column so I am only looking to copy the cells that

Solution 1:

Issue:

If you use,

ss.getRange("B2:B").copyTo(ts.getRange("A2"), {contentsOnly:true});

it always bring the value from B2 cell even if it is not visible in filtered results

Answer :

You can get the first non-filtered row number using Sheet#isRowHiddenByFilter

Snippet:

function copycolB() {
  var ss = SpreadsheetApp.getActive();
  var sourceSheet = ss.getSheetByName('Sheet1');
  var targetSheet = ss.getSheetByName('Sheet2');
  for(var row = 2; sourceSheet.isRowHiddenByFilter(row); ++row);//get first  visible row from row2var sourceRange = sourceSheet.getRange('B' + row + ':B');
  sourceRange.copyTo(
    targetSheet.getRange('A2'),
    {contentsOnly:true});
}

References:

Post a Comment for "Moving Filtered Values (copy And Paste Values) Using Google Sheet Script While Ignoring The Column Heading / Title"