Home > OS >  Change the background color of a row on selection
Change the background color of a row on selection

Time:07-01

I am new to Google Apps Script. I need advice.

I would need to create a script that changes the color of the row above which the cursor is hovering. If this isn't possible, it would be enough for me to change the background color of the entire row after clicking on any cell in that row. Is something like this possible?

Thank you for the advice.

CodePudding user response:

The best you can do with this problem is click on the first cell in the row you want to change and set up a onSelectionChange(e) function.

function onSelectionChange(e) 
{
  let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
  let selection = sheet.getActiveRange();
  sheet.getRange(selection.getRowIndex(), 1, 1, sheet.getMaxColumns()).setBackgroundRGB(255,0,0);
}

This code will highlight the line of the active cell when it is run.

  • Related