Created
November 3, 2025 18:16
-
-
Save ryanmoralesaz/a1ca5609e7e9d7c820a67ee4f309ea72 to your computer and use it in GitHub Desktop.
Cross highilight google apps script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * OPTIMIZED Cross-Highlighting - No Lag Version | |
| * Only highlights cells within your actual data range | |
| */ | |
| function onSelectionChange(e) { | |
| var ss = e.source; | |
| var sheet = ss.getActiveSheet(); | |
| var activeCell = ss.getActiveRange(); | |
| // Only work with single cell selections | |
| if (activeCell.getNumRows() > 1 || activeCell.getNumColumns() > 1) { | |
| return; | |
| } | |
| // Get the actual data range instead of max rows/columns | |
| var dataRange = sheet.getDataRange(); | |
| var lastRow = dataRange.getLastRow(); | |
| var lastCol = dataRange.getLastColumn(); | |
| // Add some padding (optional - adds 5 extra rows/cols beyond data) | |
| lastRow = Math.min(lastRow + 5, sheet.getMaxRows()); | |
| lastCol = Math.min(lastCol + 5, sheet.getMaxColumns()); | |
| // Clear previous highlights from the data range only | |
| sheet.getRange(1, 1, lastRow, lastCol).setBackground(null); | |
| var activeRow = activeCell.getRow(); | |
| var activeCol = activeCell.getColumn(); | |
| // Highlight row (only up to last column with data) | |
| if (activeRow <= lastRow) { | |
| sheet.getRange(activeRow, 1, 1, lastCol).setBackground("lightyellow"); | |
| } | |
| // Highlight column (only up to last row with data) | |
| if (activeCol <= lastCol) { | |
| sheet.getRange(1, activeCol, lastRow, 1).setBackground("lightyellow"); | |
| } | |
| // Highlight the active cell | |
| activeCell.setBackground("yellow"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment