根据另一个工作表值填充单元格

Fill cell based on another sheets value

我在 Google 张纸上有一个电子表格,其中有 2 张纸,Sheet1Sheet2。在 Sheet1 上,我有 2 列(ID1Result1),其中已填充。在 Sheet2 上,我有 2 列(ID2Result2),其中填充了 ID2,Result2 填充了单词 "empty".

我的真实电子表格中的 Sheet1 从 Google 表单获取数据,因此每次 Sheet1 收到 ID1 和 Result1 的值时,它应该在 Sheet2 的 ID2 上搜索 ID1 值,并在找到时粘贴 Result1 值在结果 2 中找到它的行。

Result2 只有在 Sheet1 上有从表单提交的新数据时才会更新。

我创建了这个可编辑的表格和电子表格,以使其更易于理解(我还在其中添加了注释以对其进行解释)。可以看到 here and the spreadsheet here.

的形式

在您的第二个 sheet 的单元格 B2 中,我输入了以下内容:

=VLOOKUP(A2,Sheet1!A:B,2,FALSE)

我想 VLOOKUP 在 Google-Sheets 上是否允许跨工作 sheet 引用?

FYI, when entering the formula, after enter the first argument which is your look up criteria, you can click your sheet1 and highlight column A and B, then go back to your sheet2 (with the second argument automatically filled by the system) to finish the formula with the third (result range column position within the look up range) and fourth argument (TRUE for approximate match and FALSE for exact match) and hit Enter to exit the formula.

像这样简单地做:

=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, Sheet1!A:B, 2, 0)))



或通过复选框重置:

看完当前的答案和评论后,我想我明白你在找什么了。

答案:

您可以在 Google Apps 脚本中执行此操作,方法是创建一个绑定到您的 Google 表单的函数,该函数收集最新响应并进行数据处理,并制作它 运行 在表单提交上。

要采取的步骤:

首先,在您的表单上,您需要创建一个绑定脚本。从表单编辑页面右上角的菜单中,单击 ⋮ > Script editor,这将打开一个新的脚本页面。

从那里你可以制作一个脚本,它会自动为你做这件事,并制作一个可安装的触发器,当你需要时 运行s。

代码:

打开脚本编辑器后,您将看到一个可以编辑的函数,如下所示:

function myFunction() {

}

用以下代码替换整个脚本:

function onSubmit(e) {
  var responses = FormApp.getActiveForm().getResponses();
  var response = responses[responses.length - 1].getItemResponses();
  var connectedSheet = SpreadsheetApp.openById('<your-sheet-id>').getSheets();
  var sheet2 = connectedSheet[1];  
  var result2Column = sheet2.getRange('A1:A').getValues();
  
  for (var i = 0; i < result2Column.length; i++) {
    if (response[1] == result2Column[0]) {
      sheet2.getRange('B' + (i +1)).setValue(response[0]);
    }
  }
}

确保将 <your-sheet-id> 替换为您的 Google 表单的唯一 ID - 您可以在 sheet 的 URL 中找到 [=15] =] 和 /edit 像这样:

https://docs.google.com/spreadsheets/d/<your-sheet-id>/edit

运行 脚本通过按播放按钮 (►) 并授权应用程序 运行.

然后转到 Edit -> Current Project's Triggers 并使用以下设置设置新的可安装触发器:

  • 选择要运行的功能:onSubmit
  • 选择应 运行 的部署:Head
  • Select 事件来源:From form
  • Select 事件类型 On form submit

解释:

每次自动提交新表单时,此脚本都会 运行 - 它会从表单响应中获取 ID 并在 Sheet2 中搜索它。如果找到,则结果的响应也将放在 Sheet2 中,在相应的 ID 旁边。

参考文献: