Reputation: 23
The image (attached) is a simple "AppScript" adapted from a popular YouTube ...that allows "Values" (in a column) to be increased by 1 - by clicking an "Arrow" (button) - that I've linked to the script
By Clicking the "Up" Arrow, all the values will change from 6 ...to 7 (ie: go "Up" by one value)
QUESTION(s): How do I 'adjust' the Script to:
And finally, if a Value is 'different' than the other values (eg: 5 ...instead of 7)
Currently, the Script will change 5 to an 8 (along with all the 7's)
I'd like the Script to change the 5 to a 6 (and the 7's can increment to 8's)
Upvotes: 0
Views: 483
Reputation: 777
You can have the script iterate through each of the value of the range and increment it if the value isn't equal to 0.
Do try this script:
function incrementA2A5() {
var sourceSheet = SpreadsheetApp.getActiveSheet();
var range = sourceSheet.getRange("A2:A5");
var values = range.getValues();
//The forEach loop below iterates through each value of the range.
//If the value isn't equal to zero, the loop will increment it by one.
values.forEach(x => x[0] != 0 ? x[0] += 1 : x[0]);
range.setValues(values); //Sets the updated values on the range
}
Upvotes: 0