Forum Discussion
RH_
May 19, 2026Occasional Reader
RH
Is it possible to select a color in Excel and highlight different cell by only clicking on them and not selecting fill the whole time?
m_tarler
May 19, 2026Silver Contributor
AFAIK this is not possible with existing excel functionality. This can be achieved using either a macro or a script. Because things are moving away from macros (IMHO) here is the code for a script that will use the currently selected cell color and then highlight every other cell you click on that same color until you click on that original cell again ...
function main(workbook: ExcelScript.Workbook) {
// Get the active cell and worksheet.
let selectedCell = workbook.getActiveCell();
let selectedSheet = workbook.getActiveWorksheet();
const origCell = selectedCell.getAddress();
const selectedColor = selectedCell.getFormat().getFill().getColor();
while (selectedCell.getAddress() == origCell) {
selectedCell = workbook.getActiveCell();
}
while (selectedCell.getAddress() != origCell) {
// Set fill color to yellow for the selected cell.
selectedCell.getFormat().getFill().setColor(selectedColor);
selectedCell = workbook.getActiveCell();
}
}
to add this click on the Automate menu item -> New Script -> Create in Code Editor
Highlight existing code and replace with the above. Click on the pencil to rename the script to whatever you want to call it. and then click save.
You then have the option to either just click on the run button from this automate menu window or you can add a button to the worksheet.