'Get values of colored rows script

enter link description here

I used this exact same script and it works, except that in my case I’m using this script for different warehouses and the sheet will only have colored rows when a certain item in the inventory reaches min stock quantity, so in my case it is possible that the sheet will not have a colored row from time to time but when it doesn’t I get a length error so when I try to use the check all warehouses button it will display each warehouse until one that doesn’t have any row colored.. hope someone can help me thanks!



Solution 1:[1]

does this work?

function iftest() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('HH 2 - Main Database'); // put the name of the source sheet
  const target_sh = ss.getSheetByName('HH 1 - New Database'); // put the name of the target sheet
  const colors = sh.getRange('F1:F').getBackgrounds().flat();
  console.log(colors);
  const values = sh.getDataRange().getValues();
  let LastRow = target_sh.getLastRow();
  const new_values = values.filter((_, i) => colors[i]=='#ff6d01');
  if(new_values && new_values.length > 0) {
    target_sh.getRange(LastRow+1,1,new_values.length,new_values[0].length).setValues(new_values);
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cooper