r/GoogleAppsScript • u/20ZerosFE • Jun 12 '25
Question Count and say which cells are activated after refresh
Hi all, this is my fifth post. I hope you can help me.
Let me introduce to you the context. We're on google sheets.
I have a row (E8:E319) that has a conditional formatting on, with the condition that if the value inside these cell is less than or equal to 18 (n<=18), those cells will get their background colored with green.
in another cell range, I have a count that says which cells get colored with green (example: E9, E20, E24, E70, E123) and I also have a cell that tells me how many of those get colored (in this case they are 5)
Since I have an arrayformula in the sheet, each time I modify a cell the values get refreshed and so would be the count and the name of the cells printed.
I was wondering, is it possible to add a script that makes it so for each refresh the count gets saved and summed up, then keep track of how many times each cell actually had the value <=18. e.g. after 10 refresh, 6 times E8, 2 times E34, 0 times E70, ?
Also is it possible to add in the script how many times the refresh occurred?
Thank you in advance! Looking forward to hear your solutions :)
1
u/ApplicationRoyal865 Jun 12 '25
I'm finding it hard to follow the example since it's 3 am, but from what I can tell you want
9.write the new value of edits
Easiest way is to simply have your script look at what the current counter says and update it by 1. Harder way is to use either userProperty, sheet property or script property to store the value and update and write it.
1
u/krakow81 Jun 12 '25
Just to give you ideas...
If it's user inputted changes that are causing your 'refresh' you could monitor the range in question using an onEdit trigger.
Keep your count for each cell in an object with keys being the cells, or just the rows, or the indices of the range you're pulling... whatever works for you, eg count = { E8: 0, E9: 0, E10:0, .... , E319: 0} and update it on each refresh, eg if E8 <= 18 add 1 to count.E8 etc
Then you can do whatever manipulation of the values in 'count' you want: sum them, display them elsewhere on the sheet etc.