- You want to count up the value of number of cell "A13" on the active Spreadsheet every 0.5 seconds.
- You want to loop the number from 0 to 360.
- You want to loop this cycle as the infinite loop.
If my understanding is correct, how about this sample script? I think that there are several answers for your situation. So please think of this as just one of them. In this sample script, I used a sidebar. Namely, I used Javascript and Google Apps Script. I thought that the infinite loop might be able to be achieved by running Google Apps Script from the sidebar. I could confirm that in my environment, this count could be run more than the maximum execution time of 6 minutes of Google Apps Script.
Usage:
When you use this script, please do the following flow.
- Copy and paste the following script to the script editor (the container-bound script of Spreadsheet).
- Run the function of
run()
.
- By this, a sidebar is opened on the Spreadsheet.
- When you click a button of "start", the number is put to the cell "A13" of the active sheet, and the value is counted up every 0.5 seconds. The number loops the cycle from 0 to 360.
- If you want to stop the count, please click "stop" button.
Sample script:
function setValue(v) {
Utilities.sleep(500);
SpreadsheetApp.getActiveSheet().getRange("A13").setValue(v);
}
function run() {
var str = '<input type="button" value="start" onclick="start()"><input type="button" id="stop" value="stop" onclick="stop=false"><script>var stop=false; function work(v){return new Promise((resolve, reject)=> google.script.run.withSuccessHandler(()=> resolve()).setValue(v));}async function start(){stop=true; var i=0; while(stop){await work(i); i=(++i) % 361;}}</script>';
var html = HtmlService.createHtmlOutput(str);
SpreadsheetApp.getUi().showSidebar(html);
}
Expanded HTML:
At above sample script, HTML is minified. Below script is the expanded HTML.
This is only for confirming HTML. So you are not required to copy and paste this.
<input type="button" value="start" onclick="start()">
<input type="button" id="stop" value="stop" onclick="stop=false">
<script>
var stop = false;
function work(v) {
return new Promise((resolve, reject) => google.script.run.withSuccessHandler(() => resolve()).setValue(v));
}
async function start() {
stop = true;
var i = 0;
while(stop) {
await work(i);
i = (++i) % 361; // This is from Dimu Designs's answer.
}
}
</script>
Note:
References:
If this method was not the direction of your goal, I apologize.
for-loop
or awhile
loop. In any case, note that there are quotas on script run time and the function won't run till the end of time.