【问题标题】:Using this Script/formula for to get value for some selected Sheets使用此脚本/公式获取某些选定表格的值
【发布时间】:2022-10-17 06:41:27
【问题描述】:

此脚本/公式将两个相邻的列添加在一起(F 列和 G 列)并将其放在 H 列中以用于 google 表格中的所有表格,我需要进一步的帮助以使其仅计算 google 表格中的一些选定表格。

function runMacro() {
  const sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  sheets.forEach(addFormula_);
}

function addFormula_(_sh) {    const formulaString = '=Filter(F2:F+G2:G,F2:F<>"")'
  const theAddress = 'H2';
  _sh.getRange(theAddress).setFormula(formulaString);

}

【问题讨论】:

    标签: google-apps-script google-sheets google-sheets-formula


    【解决方案1】:
    // By Name - Only Specified Sheets
    function runMacro() {
    
      const includeSheets = [`Sheet1`, `Sheet2`, `Sheet3`, `etc`]
    
      SpreadsheetApp.getActiveSpreadsheet().getSheets()
                    .filter(sheet => includeSheets.includes(sheet.getName()))
                    .forEach(sheet => addFormula_(sheet))
    
    }
    

    【讨论】:

    • @ NEWAZA,谢谢,它有效...但是在选定的工作表上,我不希望它计算 CELL(F2 和 G2)何时为空,请查看此链接 - drive.google.com/file/d/ 1kRZHYLCncRXZN00SAdE4NUTaEjTjly6p - 我不希望那里出现#N/A,但是当 F2 和 G2 被填充时,它应该在 H2 中输入加法。谢谢你。
    • 你好@KasimUsman!我一直在研究你的评论。主要问题是您不想计算F2G2 的值,不是吗?这些计算是在您的问题中的 addFormula_ 函数上运行的,您是否尝试过修改它?另请注意,您已经选择了一个好的答案,所以这个问题被标记为已回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    相关资源
    最近更新 更多