简体   繁体   中英

How to return a range of cells based on a value in the adjacent column in Google Sheets

I'd like to write a formula to such that it returns a range of cells from column H (unique ID) based on a criterion that is the value in column G (parent manual id). So for eg the formula should return a range of all the cells highlighted in yellow (from the image below) when the criteria in the adjacent column (column G) is 1. Similarly, the formula should return a range of all the cells highlighted in blue when the criterion (column G) is 2, and so on.

The reason, I need this to be a range of cells, is because I need to pass this resultant range as an argument into another formula (a TEXTJOIN function).

参考表

Use a query function. Make a helper column I with all unique parent manual ids column G --> unique(G2:G)

Then for the textjoin column:

=TEXTJOIN(" ",TRUE,QUERY(G$2:$H,"SELECT H WHERE G="&I2))

在此处输入图像描述

use FILTER

=FILTER(H:H; G:G=1)

and:

=FILTER(H:H; G:G=2)

and then do your TEXTJOIN for csv:

=TEXTJOIN(", "; 1; FILTER(H:H; G:G=1))

or perhaps for regex:

=TEXTJOIN("|"; 1; FILTER(H:H; G:G=2))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM