适用于所有单元格的一个 Google Sheets 宏

问题描述 投票:0回答:1

下午好。 帮我解决问题。 我有一个表(添加了屏幕),每一行都有一个复选框。复选框为真后,宏会将单元格从该复选框的行复制到单独的工作表中。

我可以为每一行写一个脚本,但这需要很多时间。帮助为整个表行范围创建宏。谢谢!!!

google-sheets macros
1个回答
2
投票

您可以使用此自定义脚本更新您的 Macro.gs 文件:

function onEdit(e) {
  if (e.value == 'TRUE') {
    const sheetNameDestination = 'Sheet2'; //Change this sheet name to your actual destination sheet

    var source = e.source.getActiveSheet().getRange(e.range.getRow(), 1, 1, e.range.getColumn() - 1);
    var destination = e.source.getSheetByName(sheetNameDestination).getRange(e.source.getSheetByName('Sheet2').getLastRow() + 1, 1, 1, source.getValues()[0].length);
    
    source.copyTo(destination)
  }
};

演示:

check this sample

© www.soinside.com 2019 - 2024. All rights reserved.