google-sheetsgoogle-sheets-formula

How to return a sub-array based on an array of row indices in Google Sheet?


How do you return a sub-array based on arrays of row indices in Google Sheet?

Example sheet looks like:

A, 1
B, 2
C, 30
D, 4
E, 50

Example inputs:

3
5

which is an array {3;5} representing the row indices of the rows I'd like to make a sub-array of the example sheet.

Desired output:

C, 30
E, 50

which is the array {C,30;E,50}.


Solution

  • You can just use CHOOSEROWS function:

    =CHOOSEROWS(A1:B,TOCOL(D1:D,1))
    

    The TOCOL function is used to skip blank rows (second argument valued 1), otherwise it will give an error in case there are any blanks in the selected range.

    enter image description here