简体   繁体   中英

Selecting specific cells from a column in excel based on another column

Here is the table that I am trying to reference from:

**A**         **B**
----------------------
TRUE          ID 100
FALSE         0
FALSE         0
FALSE         0
FALSE         0
TRUE          ID 811
FALSE         0
FALSE         0
FALSE         0
TRUE          ID 742

Basically all I want be able to do here is to list the cells in row B where row A is true. Or even where row B is not 0. So the result should look like this:

**A**          
ID 100
ID 811
ID 742

I'm sure there must be an easy way to do this but I can't seem to work it out?

Many thanks for any help in advance.

In C1 enter:

=IF( A1,1,"")

In C2 enter:

=IF(A2,1+MAX($C$1:C1),"")

and copy down. Column C "marks" the desired values. Then in D1 enter:

=IF(ROWS($1:1)>MAX(C:C),"",INDEX(B:B,MATCH(ROW(),C:C,0)))

and copy down. An example:

在此处输入图片说明

Note:

This method avoids using an array formula.

EDIT#1:

If you don't mind array formula s, then in C1 enter the array formula:

=IFERROR(INDEX($B$1:$B$15,SMALL(IF($A$1:$A$15,ROW($A$1:$A$15)-MIN(ROW($A$1:$A$15))+1,""),ROW(A1))),"")

and copy down.

Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.

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