Dashboard Mode - Creating custom menus
Goal
Create a custom menu in Google Sheets to run a script that highlights all cells with values above a threshold. This helps quickly spot important data.
Create a custom menu in Google Sheets to run a script that highlights all cells with values above a threshold. This helps quickly spot important data.
| Item | Sales |
|---|---|
| Apples | 120 |
| Bananas | 80 |
| Cherries | 150 |
| Dates | 60 |
| Elderberries | 200 |
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('Highlight')
.addItem('Highlight High Sales', 'highlightHighSales')
.addToUi();
}
function highlightHighSales() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const range = sheet.getRange('B2:B6');
const values = range.getValues();
for (let i = 0; i < values.length; i++) {
if (values[i][0] > 100) {
range.getCell(i + 1, 1).setBackground('yellow');
} else {
range.getCell(i + 1, 1).setBackground(null);
}
}
}+---------------------------+
| Google Sheet |
| +-----------------------+ |
| | Item | Sales | |
| |--------|--------------| |
| | Apples | 120 | |
| | Bananas| 80 | |
| | Cherries| 150 | |
| | Dates | 60 | |
| | Elderb.| 200 | |
| +-----------------------+ |
| |
| Custom Menu: "Highlight" |
| - Highlight High Sales |
+---------------------------+When the sheet opens, the onOpen function adds the custom menu. Clicking Highlight High Sales runs the script that colors sales above 100 in yellow. This updates the sheet visually to show important data.
If you change the sales value for "Bananas" to 130 and run Highlight High Sales again, which cells will be highlighted?