Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Last active October 14, 2023 10:53
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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

@kenomd
Copy link

kenomd commented Jan 2, 2022

Help, I copied and pasted the code, and set triggers but code doesn't work.

@tanaikech
Copy link
Author

@kenomd Thank you for your comment. I have to apologize for my poor English skill. Unfortunately, from Help, I copied and pasted the code, and set triggers but code doesn't work., I cannot understand your current situation. Because when I tested my sample script, unfortunately, I can confirm that the script works fine. This is due to my poor skill. I deeply apologize for this. In order to correctly understand your issue, can you provide the detailed flow for correctly replicating your issue? By this, I would like to confirm it. If you can cooperate to resolve your issue, I'm glad. Can you cooperate to do it? By the way, also I cannot understand set triggers in your comment.

@kenomd
Copy link

kenomd commented Jan 3, 2022 via email

@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