简体   繁体   English

谷歌表格谷歌应用程序脚本为所有行添加 VLOOKUP 函数

[英]Google Sheets google apps script add a VLOOKUP function for all rows

I have a sheet with a number of VLOOKUPS which do work BUT whenever a new row is added the VLOOKUP formula is not added to the new row.我有一张带有许多 VLOOKUPS 的工作表,它们确实可以工作,但是每当添加新行时,VLOOKUP 公式都不会添加到新行中。 I'm certain this can be done with app script but I don't know exactly where to start.我确定这可以通过应用程序脚本完成,但我不知道从哪里开始。

It is important (OK vital) that the VLOOKUPs are on every row even new rows when added.重要的是(确定至关重要)VLOOKUP 在每一行上,即使添加时也是新行。 I do have a duplicate row function that operates from a custom menu but I know that some users will use the default Google Add "X" rows button which does not replicate functions.我确实有一个从自定义菜单操作的重复行功能,但我知道有些用户会使用不复制功能的默认 Google 添加“X”行按钮。

 function onOpen() {
   SpreadsheetApp.getUi() 
      .createMenu('custom menu')
      .addItem('Add rows','duplicateLastRow')
      .addSeparator()
      .addItem('Help','showSidebar')
      .addToUi();
}

function duplicateLastRow(){
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
  ss.insertRowsAfter(ss.getLastRow(),10);
  ss.getRange(ss.getLastRow(),1,1,ss.getLastColumn()).copyTo(ss.getRange(ss.getLastRow()+1,1,10));
}

Here is one of the VLOOKUPS =if(A2 > 0,VLOOKUP(A2,Sheet2!A$2:G,3,false),"")这是 VLOOKUPS =if(A2 > 0,VLOOKUP(A2,Sheet2!A$2:G,3,false),"")之一

What I'm looking for is whenever a row in Col A is updated/added the VLOOKUP runs via a script as I understand that would ensure it applies to all rows, even new ones when added that way I don't need the duplicate row function.我正在寻找的是每当更新/添加 Col A 中的一行时,VLOOKUP 通过脚本运行,据我所知,这将确保它适用于所有行,即使是新行,以这种方式添加我不需要重复的行功能。

How do I structure the script function - thanks in advance如何构建脚本功能 - 在此先感谢

Google Sheet use ArrayFormula for only a cell to calculate the Vlookup for a range Google Sheet 仅对一个单元格使用ArrayFormula来计算一个范围的 Vlookup

Formula for you给你的公式

=ArrayFormula(if(A2:A>0,VLOOKUP(A2:A,Sheet2!A$2:G,3,0),""))

Note: Make sure the other cells below the cell containing the ArrayFormula are cleared.注意:确保清除包含 ArrayFormula 的单元格下方的其他单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM