Google Spreadsheets function to get a cell from a range by row and col name

a 夏天 提交于 2019-12-04 21:05:03

Try this, you just need to set ranges:

=INDEX("Talbe",MATCH("foo","First Column",0),MATCH("idz04","First Row",0))

For example if your table is in the range A1:D4, use:

=INDEX(A1:D4,MATCH("foo",A:A,0),MATCH("idz04",1:1,0))

You can also use named ranges


To get first columns and rows automatically use this formula:

=INDEX(data,MATCH("foo",INDIRECT(CHAR(64+COLUMN(data))&":"&CHAR(64+COLUMN(data))),0),MATCH("idz04",INDIRECT(COLUMN(data)&":"&COLUMN(data)),0))

To do this via script, use this code:

function LOOKUPGRID(data, rowHeader, colHeader) {
  for (var i = 0; i<data.length;i++) {
    if (data[i][0] === rowHeader) {
      for (var j = 0; j<data[0].length;j++) {
        if (data[0][j] === colHeader) {
          return (data[i][j]);
        }
      }
    }
  }
  return (null)
}

You can then call the formula in your sheet like this:

=LOOKUPGRID(A1:D4,"foo","idz04")

For this you could write a custom function using Google Apps Script. Check this documentation for more details.

You could access the spread sheet with name or id and get the range of values(in your case a cell).

Hope that helps!

Ondra Žižka

Here it goes:

=INDEX(ObjednavkyData, 
   // Find the offset of "vesela01" in the 1st column
   MATCH("vesela01",
     OFFSET((ObjednavkyData),0,0,
        MAX(ARRAYFORMULA(ROW(ObjednavkyData)))  // Num of rows in the range
     , 1)
   ,0), 
   // Find the offset of "z03" in the 1st row
   MATCH("z03", 
     OFFSET(ObjednavkyData, 0 , 0, 1)  // First row
   , 0)) 

Not really neat :P
Also see Google Spreadsheets: How to get a first (Nth) row/column from a range? (built-in functions)

Tried to write my own function...

/**
 * Returns [Range] the cell value at coordinates determined by the values first row (colHeader) and first column (rowHeader) in given range.
 */ 
function LOOKUP_GRID(range, colHeader, rowHeader){
  for(var col = range.getWidth()-1; col--; col  >= 0 )
    if(range.getCell(1, col).getValue() === colHeader)
      break;
  for(var row = range.getHeight()-1; row--; row  >= 0 )
    if(range.getCell(row, 1).getValue() === rowHeader)
      break;

  if(col === -1 || row === -1)
    return null;
  else
    return range.getCell(row, column)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!