Hey everyone,
I'm looking to create a script for Google Sheets that will check if there is a value in a cell within a row, and then populate another cell in the same row with a specific value. For instance, if a cell in row 2, column G contains anything other than empty quotes, I want to write "New issue" in the corresponding cell on row 2, column C. Here's what I have so far:
// Goal: Fill cells in Column G based on values in other cells in the same row
function formatSpreadsheet() {
var sheet = SpreadsheetApp.getActive();
var data = sheet.getRange("C3:1000").getValues();
if (data !== "") {
sheet.getRange("G3:G1000").setValue("New Issue");
}
}
The issue with my current code is that it writes "New Issue" to all cells in the range G3-G1000 if any value is found in C3-C1000. What I actually need is for it to only update the corresponding row in column G when a value exists in the respective row of column C. So, if C4 has a value, G4 should be set to "New issue", and so on for each row.
Hopefully, this clarifies things, but feel free to ask me to provide more details. I'm unsure whether using IF statements or implementing a forEach loop would be more appropriate in this situation. I'm not very familiar with how to use forEach, unfortunately. Thanks a lot for your assistance!