MuffiZainu
MuffiZainu

Reputation: 11

Google spreadsheet auto highlight

In Google Drive, I have a huge Spreadsheet file. 6 people will be working on multiple rows.

There will be one column and in it each person will write their intials, example HJ, MZ etc. When they write it, I want it to automatically highlight the entire row in a specific color

Example:

and so on. How do I go about doing it?

Upvotes: 1

Views: 972

Answers (1)

julumme
julumme

Reputation: 2366

I have done something similar with my script. I have some restrictions on what to color, but I think you can easily see how to modify that to your purpose (coloring full row etc)

Just change my "comparison strings" from "Ready" etc to "MZ", and you should be golden

Code:

function colorRow(r){
  var sheet = SpreadsheetApp.getActiveSheet();

  //I only want to color the row starting from 2nd column, up to 6th
  var dataRange = sheet.getRange(r, 2, 1, 6);
  var data = dataRange.getValues();
  var row = data[0];

  //If empty, set white
  if(row[0] === ""){ 
    dataRange.setBackgroundRGB(255, 255, 255);

  //Rows needing checking, blue
  } else if(row[0] === "Check"){
    dataRange.setBackgroundRGB(153, 186, 247);

  //Completed green
  } else if(row[0] === "Ready"){
    dataRange.setBackgroundRGB(192, 255, 192);

  //Others red
  } else{
    dataRange.setBackgroundRGB(255, 192, 192);
  }
  SpreadsheetApp.flush();
}

//Called by system after every edit
function onEdit(event)
{ 
    colorRow(event.source.getActiveRange().getRowIndex());
}

Hope it helps!

Edit: Corrected a mistake in the onEdit() function.

Upvotes: 1

Related Questions