# How to change the value of cell automatically when meet some criteria in google sheet

Solution for How to change the value of cell automatically when meet some criteria in google sheet
is Given Below:

I am working on creating result key in template and I have just one last task that I cannot figure out. Here is an example of what I would like to accomplish.

If A3 = Monday, Thursday, Friday or Sunday, when the people key in less than or equal 0.05 at the range A7:A30, the value will change to 0.01 automatically and if the value is more than 0.05, the value will remain the same. If A3 = Tuesday, Wednesday or Saturday, the value at the range will remain the same, not matter what value it is.

Is that any script or formula in google sheet can do this kind of task?

This picture below is showing the template.

Key in template

• You should no quote numbers (`0.05` `0.01`)
• You `return` in `if(value <= 0.05 & value !="")` so only the first matching row would be overwritten
• `targetSunday != "Monday"` typo
• `targetDate` condition outside `for` loop would look smarter
• `row` (actually arrayIndex or rowIndex) starts from `0`
`````` function changeValue(){
var sheet = ss.getActiveSheet();

var targetDate = sheet.getRange('A3').getValue();
if(!["Monday", "Thursday", "Friday", "Sunday"].includes(targetDate)) { return; }

var targetRange = sheet.getRange('A7:A30');
var values = targetRange.getValues();
for(var row = 0; row < values.length; row++) {
var value = values[row];
if(value <= 0.05 & value !="") {
value = 0.01;
values[row] = value;
}
}
targetRange.setValues(values);
}
``````

Is that something like this?

``````function onEdit() { changeValue(); }

function changeValue(){
var sheet = ss.getActiveSheet();

var targetDate = sheet.getRange('A3').getValue();
if(!["Monday", "Thursday", "Friday", "Sunday"].includes(targetDate)) { return; }

var targetRange = sheet.getRange('A7:A30');
var values = targetRange.getValues();
for(var row = 0; row < values.length; row++) {
var value = values[row];
if(value <= 0.05 && value !="") {
value = 0.01;
values[row] = value;
}
}
targetRange.setValues(values);
}
``````