簡體   English   中英

您能否使用 function 輸入根據列和行中的值找到一個值?

[英]Can you find a value based on value in column and row with a function input?

我一直在尋找一個可以創建自定義 function 的示例,我可以在其中放入兩個值並從另一張表中查看單元格值。 例如,在屏幕截圖“monthTest”中,我們輸入“Credit Card Fees”和“1/1/21”,然后它會在工作表 sumActuals 上查找並返回 360,因為 A 列中的“Credit Card Fees”與輸入匹配“Credit Card Fees”和“1/1/21”與 sumActuals 表中第 1 行的“1/1/21”匹配。

輸入自定義 function 的工作表在此處輸入圖像描述

自定義 function 查找值的工作表在此處輸入圖像描述

https://docs.google.com/spreadsheets/d/17SId7mIzO3hVOC36Nq40O0bjPS5YfGOX4wsMU1NlbCU/edit?usp=sharing

function lookup(col1, header) {
  if (col1 && header) {
    const ss = SpreadsheetApp.getActive();
    const sh = ss.getSheetByName('monthTest');
    const [hA, ...vs] = sh.getDataRange().getValues();
    let col = {};
    hA.forEach((h, i) => col[h] = i + 1);
    for (let i = 0; i < vs.length; i++) {
      if (vs[i][0] == col1) {
        //Logger.log(sh.getRange(i + 2, col[header]).getValue());
        return sh.getRange(i + 2, col[header]).getValue();
      }
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM