Select entire row when cell is active

How to develop a sheet script that would highlight the active line?

I would like the whole row to change the font or background color when one cell in that row is active.

I don’t want the trigger to be any specific value in the cell, just clicking on the cell should cause selection for the entire row to which the cell belongs.

+11
source share
4 answers

Sorry, this cannot be done with conditional formatting or a script just by selecting a cell. However, you can select an entire row of the active cell using the Shift-Spacebar key combination.

+18
source

I understand that this question was asked some time ago, but I came across it when I was looking for the same function. My solution is a bit cumbersome and not a complete solution for what you are looking for, but it combines both a tiny script and a bit of conditional formatting.

First, I wrote a small script using the onEdit () function:

function onEdit(e) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getActiveSheet(); var targetCell = sheet.getRange('AD1'); var activeCell = e.range.getA1Notation(); targetCell.setValue(activeCell); } 

I chose β€œAD1” as the target cell, since it was far to the side and, if necessary, I could also hide this column.

Then I moved on to conditional highlighting and typed this as a user formula:

 =ROW()=ROW(INDIRECT($AD$1)) 

Voila! Every time I edit a cell, it automatically selects this whole row.

This is not quite what you are looking for, as it will not automatically highlight the entire row as soon as you click on a cell ... only when editing a cell. Also, if you have other running formulas and other conditional formatting, your spreadsheet may start slowly. But this is the closest I saw there to a possible solution.

Much less than cool, but still somewhat functional with respect to readability - this is the main highlight of every other line. For instance:

in conditional formatting: =ROW()=EVEN(ROW())

+3
source

The problem you are describing can be resolved indirectly through a checkbox.

  1. Insert column A into the table.
  2. In column A, select the cells in the rows that you want to highlight.
  3. From the Insert menu, select Check Box .
  4. Select the entire lines in which the check box was selected.
  5. From the Format menu, select Conditional Formatting .
  6. In the Formatting Rules pane, add the Custom formula to this rule .
  7. Enter the formula =$A1=TRUE (instead of 1, use the first line number selected in step 4).
  8. Specify a formatting style .

From now on, after checking the box, the entire line will be highlighted.

0
source

Unfortunately, this cannot be done with onFocus, as we all would like, but it works quite well for me using the onEdit event. It's still weirdly slow, so maybe someone could do it faster (of course, from read / write to properties, but this is the only way I found to track which line is highlighted).

 function onEdit(e){ manageRowHighlight(e); } function manageRowHighlight(e) { var props = PropertiesService.getScriptProperties(); var prevRow = parseInt(props.getProperty('highlightedRow')); var range = e.range; var thisRow = range.getRow(); //if it same row, just ignore if (prevRow == thisRow) { return; } else if (prevRow != null){ //else unhighlight it range = range.getSheet().getRange(prevRow + ':' + prevRow); range.setBackground(null); } //highlight the current row var range = range.getSheet().getRange(thisRow + ':' + thisRow); range.setBackground('#fff2cc') //save the row so highlight can be removed later props.setProperty('highlightedRow', thisRow); }; 
0
source

All Articles