在列中查找值,使用该信息,然后停止搜索
Find value in column, use that information, and stop searching
我有一个 Google 表格,其中包含一些列和行的信息。我想在第一列中查找 "specific text" 并在另一个选项卡中写入内容,但我不想在该列中继续搜索。只需要知道特定文本是否出现即可。示例:
SPOTFIRE Peter
SMARTWEB Mike
SMARTWEB Mike
X9CLARA John
我想查找文本 SMARTWEB
并将单词 found
放在不同的选项卡中。
这是一个简单的脚本:
var Spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var Sheet1 = Spreadsheet.getSheetByName("Sheet one");
var Sheet2 = Spreadsheet.getSheetByName("Sheet two");
var Lastrow = Sheet1.getLastRow();
for (var i=1; i<=Lastrow; i++){ //check all the rows of that column
var Check = Sheet1.getRange(i,1).getValue();
if (Check == "SMARTWEB"){ //check the cell value of each row
Sheet2.getRange(3,1).setValue("found"); //write the text in the target cell
}
}
问题是此脚本将继续在所有行中查找 SMARTWEB
值。想象一下我有 10,000 行,这将花费很多时间。我只需要一个脚本来知道 "in all the column rows" 我是否有值 SMARTWEB
。我不在乎位置或任何其他细节。只知道是否出现在列中,在不同的sheet.
中写found
有没有更简单的方法?
提前致谢。
你能不能只使用这样的公式:
=SUM(ArrayFormula(IFERROR(SEARCH("SMARTWEB",Sheet1!A:A))))
正数表示该字符串存在于 Sheet1 的 A 列中,而零表示它不存在
我有一个 Google 表格,其中包含一些列和行的信息。我想在第一列中查找 "specific text" 并在另一个选项卡中写入内容,但我不想在该列中继续搜索。只需要知道特定文本是否出现即可。示例:
SPOTFIRE Peter SMARTWEB Mike SMARTWEB Mike X9CLARA John
我想查找文本 SMARTWEB
并将单词 found
放在不同的选项卡中。
这是一个简单的脚本:
var Spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var Sheet1 = Spreadsheet.getSheetByName("Sheet one");
var Sheet2 = Spreadsheet.getSheetByName("Sheet two");
var Lastrow = Sheet1.getLastRow();
for (var i=1; i<=Lastrow; i++){ //check all the rows of that column
var Check = Sheet1.getRange(i,1).getValue();
if (Check == "SMARTWEB"){ //check the cell value of each row
Sheet2.getRange(3,1).setValue("found"); //write the text in the target cell
}
}
问题是此脚本将继续在所有行中查找 SMARTWEB
值。想象一下我有 10,000 行,这将花费很多时间。我只需要一个脚本来知道 "in all the column rows" 我是否有值 SMARTWEB
。我不在乎位置或任何其他细节。只知道是否出现在列中,在不同的sheet.
found
有没有更简单的方法?
提前致谢。
你能不能只使用这样的公式:
=SUM(ArrayFormula(IFERROR(SEARCH("SMARTWEB",Sheet1!A:A))))
正数表示该字符串存在于 Sheet1 的 A 列中,而零表示它不存在