var userProperties = PropertiesService.getUserProperties();
var H_MODE = 'M';
function getMode() {
return userProperties.getProperty(H_MODE);
}
function setMode(m) {
userProperties.setProperty(H_MODE,m);
}
function createHighlightMenu() {
setMode('off');
SpreadsheetApp
.getActiveSpreadsheet()
.addMenu('Highlight', generateMenu());
}
function updateHighlightMenu() {
SpreadsheetApp
.getActiveSpreadsheet()
.updateMenu('Highlight', generateMenu());
}
function generateMenu() {
return [
{name: (getMode()=='off'? " ✓ " :'')+'Off', functionName: 'setOff'},
{name: (getMode()=='row'? " ✓ " :'')+' Highlight row', functionName: 'setHighlightRow'},
{name: (getMode()=='column'? " ✓ " :'')+' Highlight column', functionName: 'setHighlightCol'},
{name: (getMode()=='crosshair'? " ✓ " :'')+' Highlight crosshair', functionName: 'setHighlightCrosshair'}
];
}
function setOff() {
setMode('off');
updateHighlightMenu();
}
function setHighlightRow(){
setMode('row');
updateHighlightMenu();
}
function setHighlightCol(){
setMode('column');
updateHighlightMenu();
}
function setHighlightCrosshair(){
setMode('crosshair');
updateHighlightMenu();
}
function highlight(type) {
const ss = SpreadsheetApp.getActive();
const s = ss.getActiveSheet();
const a = ss.getActiveCell();
const col = a.getColumn();
const row = a.getRow();
const maxColumns = s.getMaxColumns();
const maxRows = s.getMaxRows();
const c = s.getRange(1, col, maxRows, 1);
const r = s.getRange(row, 1, 1, maxColumns);
const ar = s.getRange(row, col);
var ranges = [];
if (type != 'column') ranges.push(r.getA1Notation());
if (type != 'row') ranges.push(c.getA1Notation());
ranges.push(ar.getA1Notation());
console.log('Ranges ',ranges);
s.getRangeList(ranges).activate();
console.log('Active sheet ',s.getName());
console.log('Active', s.getActiveRangeList());
}
function highlightRow() {
highlight('row');
}
function highlightColumn() {
highlight('column');
}
function highlightCrosshair() {
highlight('crosshair');
};
// Uncomment this function if you need
function onSelectionChange(e) {
console.log('onSelChange',getMode());
highlight(getMode());
}
A small addition to https://jec.fyi/blog/highlight-apps-script code