google-sheetsgoogle-sheets-formula

If a column has any cell with a color, change the entire row of that column to that same color, Google Sheets


I've been trying to find out how to do this all day and I tried, everything. I have a Column that has some cells with a background color (Column B.) The sheet has 600 Rows, so Column B goes down to B600, and has columns from A-H. Let's say random rows in B have a color (only one color, let's say blue), let's say cells B4, B7, B11 have a Blue background color. I'm trying to find a way to make it so that the entire row of cells B4, B7, B11 also become Blue. I'd do it manually, but I have a lot of projects like this coming up, and it's not just those 3 rows, it's 100+ cells in that column that have a color.

I've tried setting the range to A1:H6 in conditional formatting, and choosing the "custom formula is" option and set it to:

=OR(ISCOLOR(B1:B600))

I tried other ways as well, one of which is using this:

=OR(B1=0000FF and giving it different ranges like b1:b600

Any help with trying to make this work?


Solution

  • A sheet has a data range of A1:H600. Some "random" cells in Column B have a "blue" background colour ("#0000ff"). For those cells, it is necessary to set the background colour for the entire row to "blue".

    Try this script:


    function setRowColors() {
      var ss = SpreadsheetApp.getActiveSpreadsheet()
      var sheet = ss.getSheetByName("Sheet1")
      
      // get the background colours in Column B
      var range = sheet.getRange('B1:B600')
      var bgColors = range.getBackgrounds()
      
      // loop though Column B
      for (var i=0;i<bgColors.length;i++){
        // if background colour = Blue, then set the whole row as blue
        if (bgColors[i][0] == "#0000ff"){
          sheet.getRange((i+1),1,1,8).setBackground("#0000ff")
        }
      }
    }