P
P
pcassidy5422021-10-03 01:48:42
Google Apps Script
pcassidy542, 2021-10-03 01:48:42

Script to replace cells if a condition is met?

Hello, tell me how to implement a script so that cells are replaced when the condition matches.
In a simple example,
there are 2 columns A and B.
In column A there are empty cells or with the text "Job"
it is necessary that "Job" be inserted into column B opposite in those cells where "Job" is written in the adjacent cell of column A.
it is desirable that it spread to the entire table (for example, columns AA AB can have the same values)
We need a script, not a formula, because I have a little different data and gave such an example.

upd: I made such a script, but it only works when editing, i.e. when I manually wrote "Work", then everything will work, how to make it look at the entire table and even where it already exists, then change it. And it is necessary that this does not happen automatically, but when I myself click (like triggers, as I understand it)
function onEdit() {

var sheetNameToWatch = "TEST";
var valueToWatch="Work";
varsheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
var val=sheet.getActiveCell().getValue()

if (sheet.getName() == sheetNameToWatch && (val== valueToWatch )) {
var targetCell = sheet.getRange(range.getRow(), range.getColumn()- one);
targetCell.setValue("Job" );
}

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2021-10-03
@ProgrammerForever

  1. Get a list of sheets. For each:
  2. Get dataRange , get data
  3. For each cell in the data, from right to left:
  4. Check for a value, if it is - change the right cell to the desired one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question