Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Last active October 14, 2023 10:53
Show Gist options
  • Save tanaikech/3e6b6bbc13cd9814aa918c9933fb862f to your computer and use it in GitHub Desktop.
Save tanaikech/3e6b6bbc13cd9814aa918c9933fb862f to your computer and use it in GitHub Desktop.
Highlighting Row and Column of Selected Cell using Google Apps Script

Highlighting Row and Column of Selected Cell using Google Apps Script

This is a sample script for highlighting the row and column of the selected cell using Google Apps Script. For this, the OnSelectionChange event trigger is used.

Demo

Sample script

Please copy and paste the following script to the script editor of Spreadsheet. And, please select a cell. By this, the script is run by the OnSelectionChange event trigger.

function onSelectionChange(e) {
  const range = e.range;
  const sheet = range.getSheet();
  const maxRows = sheet.getMaxRows();
  const maxColumns = sheet.getMaxColumns();
  sheet.getRange(1, 1, maxRows, maxColumns).setBackground(null);
  sheet.getRange(1, range.getColumn(), maxRows, 1).setBackground("yellow");
  sheet.getRange(range.getRow(), 1, 1, maxColumns).setBackground("yellow");
}

References

@tanaikech
Copy link
Author

Thank you for replying. I'm glad your issue was resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment