Google Spreadsheets: How to get a first (Nth) row/column from a range? (built-in functions)

前端 未结 4 758
攒了一身酷
攒了一身酷 2020-12-30 23:56

Say I have this named range, not at A1.

      idz01  idz04  ida02
foo     a      1      b
bar     c      3      8
baz     8      2      g

N

相关标签:
4条回答
  • 2020-12-31 00:44

    Partial answer: (still open to better ones)

    1st row

    OFFSET(Data, 0 , 0, 1)
    

    First column:

    You simply can call some functions on the range and they take 1st column.
    Or, if needed:

    OFFSET(Data, 0, 0, MAX(ARRAYFORMULA(ROW(Data))), 1)
    

    Nth row:
    The key here is that OFFSET() only fills right and down. So you only need to crop these directions by it's parameters.

    OFFSET(Data, N, 0, 1);
    

    Could be also achieved by feeding the first row to ARRAYFORMULA() and for each column (cell), get the last row's cell using INDEX(COLUMN(),ROW() + N).

    Nth column:

    Similarly to above, only you need to get the number of rows.

    OFFSET(Data, 0, N, ROWS(Data), 1);
    

    I was playing with TRANSPOSE() but seems that OFFSET() doesn't digest it well.

    0 讨论(0)
  • 2020-12-31 00:52

    I would like to propose an alternative method, that works also with volatile unnamed ranges (e.g. output from other functions, not just ranges that exist on the spreadsheet.) The general idea is to use FILTER() as the mechanism of extractions, and construct a vector of true/false values as an indicator of which rows to extract. So for instance, if the source range is A1:D13 and I want to extract row 7, I would write

    =filter(
       A1:D13,
       {transpose(split(rept("0 ", 6), " "));
        1;
        transpose(split(rept("0 ", rows(A1:D13)-7), " "))
       }
      )
    

    As you can see, it's also easy to generalize to extracting any number of rows from anywhere. In general terms construct the formula like that:

    =filter(
       <data>,
       {transpose(split(rept("0 ", <number rows to skip from the start>), " "));
        transpose(split(rept("1 ", <number of rows to extract>), " "));
        transpose(split(rept("0 ", <number of rows to skip until the end), " "))
       }
      )
    
    0 讨论(0)
  • 2020-12-31 00:52

    First Row:

    =INDIRECT(COLUMN(data)&":"&COLUMN(data))
    

    First Column:

    =INDIRECT(CHAR(64+COLUMN(data))&":"&CHAR(64+COLUMN(data)))
    

    N'th row:

    =INDIRECT(COLUMN(data)+N&":"&COLUMN(data)+N)
    

    N'th Column:

    =INDIRECT(CHAR(64+COLUMN(data)+N)&":"&CHAR(64+COLUMN(data)+N))
    

    Substitute data with your data range and N with the row/column that you need in the data. Row's/Column's are counted starting with 0. You can change that buy using N-1 instead.

    If you want to get the actual range (A:A,1:1,A3:A3) instead of the values, just ged rid of the INDIRECT in these formulas

    Hope this helps

    0 讨论(0)
  • 2020-12-31 00:58

    Just use the INDEX function:

    =INDEX(NamedRange1,NRow,NColumn)
    

    If you want the last row and column you can use:

    =INDEX(NamedRange1,ROWS(NamedRange1),COLUMNS(NamedRange1))
    
    • INDEX is more efficient than the alternative OFFSET and INDIRECT that are volatile.

    Examples:

    =INDEX(ObjednavkyData,3,2) //This will return "c".
    =INDEX(ObjednavkyData,ROWS(ObjednavkyData),COLUMNS(ObjednavkyData2)) //This will return "g".
    

    Addition:

    If you want to get the whole row, you can omit the column part of the INDEX function. And if you need the whole column, omit the row part (by putting 0 in the row field).

    =INDEX(ObjednavkyData,3)    //This will return row 3:    "bar       c      3      8".
    =INDEX(ObjednavkyData,0, 2) //This will return column 2: "idz01     a      c      8".
    
    0 讨论(0)
提交回复
热议问题