Home > database >  How to toggle cell color when clicking on that cell
How to toggle cell color when clicking on that cell

Time:11-01

I'm trying to find function that will change (toggle) cell color when you would click on it.

For example, I have cell that that only has number "1" on it and it's default color is white, so when I click that cell (like you would on click on a checkbox) the color should now be blue. If you would click it again, the color should go back to white etc.

What I tried so far:

  • Using Dta validation to change checkbox value to text so that both TRUE and FALSE statements simply are written as number 1, but I got validation error that both states couldn't be named the same
  • Using Conditional formatting. so when checkbox is checked, color of that cell is changed (this works to some degree, but for some reason not when I use it together with Data validation)

Does anyone have solution on how should I approach this?

CodePudding user response:

In theory it could be possible with the onSelectionChange trigger on an apps script function. It could be a simple function that:

  1. Gets the selected or active cell range
  2. If the background color is white, changes it to blue
  3. If the color is already blue, changes it back to white

Changing color is already doable with the setBackground function.

  • Related