读取单元格"a"的Google表格脚本并将其写入单元"b".基于关闭的单元"a"价值 [英] Google Sheet script that reads cell "a" and writes to cell "b" based off cell "a" value

查看:63
本文介绍了读取单元格"a"的Google表格脚本并将其写入单元"b".基于关闭的单元"a"价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,

我需要为Google表格编写一个脚本,该脚本检查行中的单元格是否包含值,它将向该行的列中写入值.例如,如果第2行第2列的单元格中的单元格的值不是",则在第2行第C列的单元格中写新问题".到目前为止,我有以下内容:

I need to write a script for Google Sheets that checks if a cell in the row contains a value it will write a value to a column on that row. For example, If cell in row 2, column G has a value other than "" write "New issue" in cell on row 2, column C. I have this so far:

// Purpose: To populate cell in Column G if another in row cell contains 
// something other than null, or ""

function formatSpreadsheet() {
  var sheet = SpreadsheetApp.getActive();
  var data = sheet.getRange("C3:1000").getValues();

  if (data !== "") {
    sheet.getRange("G3:G1000").setValue("New Issue");

  }
}

与此有关的问题是,如果在C3-C1000中找到一个值,则它将"New Issue"写入到G3-G1000范围内的所有单元格中.我需要它只将其写入相应行的位置.因此,如果C4具有值,则G4应设置为新问题",而C5具有值,则G5应设置为新问题",等等.

The problem with this is that if a value is found in C3 - C1000, it writes "New Issue" to all cells in range G3 - G1000. I need it to where it only writes it to that corresponding row. So if C4 has a value, G4 should be set to "New issue" and if C5 has a value then G5 should be set to "New issue", etc.

希望这是有道理的,我可以尝试尽可能多地清除它.我不知道"IF语句"在这种情况下是否有帮助,或者每个循环是否需要a.我可悲的是我不知道该如何使用.谢谢您的帮助!

Hopefully this makes sense, I can try to clear it up as much as possible. I don't know if "IF statements" are helpful in this scenario or if I need a for each loop. I don't know how to use for each though sadly. Thank you for your help!

推荐答案

结果证明,一个简单的公式无需脚本即可自行完成.

Turns out a simple formula can do this on it's own without a script.

"== ArrayFormula(if(len(C2:C)," New Issue,))"就够了.

"=ArrayFormula(if(len(C2:C),"New Issue",))" is all it takes.

这篇关于读取单元格"a"的Google表格脚本并将其写入单元"b".基于关闭的单元"a"价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆