Реализация vlookup и соответствие в функции - PullRequest
0 голосов
/ 02 июля 2019

Я пытаюсь создать в Sheets функцию, которая объединяет часто используемые комбинации «Vlookup» и «Match».

Я хочу использовать мою функцию "Rates", чтобы принять 1 аргумент и вернуть комбинацию Vlookup и Match, которая всегда использует одни и те же значения.

Vlookup (аргумент, DEFINED RANGE (всегда остается в одном и том же определенном диапазоне), соответствует (A1 (всегда ячейка A1), DIFFERENT DEFINED RANGE, 0), FALSE)

Я пытался создать сценарий, но у меня нет опыта кодирования, и я получаю сообщение об ошибке "vlookup is notfined"

function ratesearch(service) {
  return vlookup(service, Rates, Match($A$1,RatesIndex,0),FALSE);
}

Фактические результаты: #ERROR!

ReferenceError: "vlookup" не определено. (строка 2).

Я смог решить мою проблему, используя следующее:

function findRate() {
  var accountName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(1,1).getValue(); //determine the account name to use in the horizontal search
  var rateTab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Rates'); //hold the name of the rate tab for further dissection
  var rateNumColumns =rateTab.getLastColumn(); //count the number of columns on the rate tab so we can later create an array
  var rateNumRows = rateTab.getLastRow(); //count the number of rows on the rate tab so we can create an array
  var rateSheet = rateTab.getRange(1,1,rateNumRows,rateNumColumns).getValues(); //create an array based on the number of rows & columns on the rate tab
  var currentRow = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveCell().getRow(); //gets the current row so we can get the name of the rate to search
  var rateToSearch = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(currentRow,1).getValue(); //gets the name of the rate to search on the rates tab
  for(rr=0;rr<rateSheet.length;++rr){
    if (rateSheet[rr][0]==rateToSearch){break} ;// if we find the name of the 
      }
  for(cc=0;cc<rateNumColumns;++cc){
    if (rateSheet[0][cc]==accountName){break};
      }
  var rate = rateSheet[rr][cc] ; //the value of the rate as specified by rate name and account name
  return rate;
}

Ответы [ 2 ]

0 голосов
/ 07 июля 2019
function findRate() {
  var accountName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(1,1).getValue(); //determine the account name to use in the horizontal search
  var rateTab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Rates'); //hold the name of the rate tab for further dissection
  var rateNumColumns =rateTab.getLastColumn(); //count the number of columns on the rate tab so we can later create an array
  var rateNumRows = rateTab.getLastRow(); //count the number of rows on the rate tab so we can create an array
  var rateSheet = rateTab.getRange(1,1,rateNumRows,rateNumColumns).getValues(); //create an array based on the number of rows & columns on the rate tab
  var currentRow = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveCell().getRow(); //gets the current row so we can get the name of the rate to search
  var rateToSearch = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(currentRow,1).getValue(); //gets the name of the rate to search on the rates tab
  for(rr=0;rr<rateSheet.length;++rr){
    if (rateSheet[rr][0]==rateToSearch){break} ;// if we find the name of the 
      }
  for(cc=0;cc<rateNumColumns;++cc){
    if (rateSheet[0][cc]==accountName){break};
      }
  var rate = rateSheet[rr][cc] ; //the value of the rate as specified by rate name and account name
  return rate;
}
0 голосов
/ 02 июля 2019

vlookup - это не то, что вы можете использовать в функции в скрипте, это формула электронной таблицы.

Google Scripts использует JavaScript, поэтому вам нужно написать свой код в JS, а затем вывести его в соответствующую ячейку.

Если бы вы могли поделиться своим листом / сценарием, мы могли бы помочь выяснить это с вами.

...