Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

excel - Searching rows for two entries and returning the successful results (adapting existing code)

I am currently using this code in Excel to find and return, via an array, the results of a search but I need to adapt it to search based on two criteria instead of one and would appreciate some help adjusting the code to do that.

Here's what I have...

=IF(ISERROR(INDEX($B$1:$F$154,SMALL(IF($B$1:$B$154="Good",ROW($B$1:$B$154)),ROW(1:1)),5)),"",INDEX($B$1:$F$154,SMALL(IF($B$1:$B$154="Good",ROW($B$1:$B$154)),ROW(1:1)),5))

It currently searches B1:B154 to look for the entry "Good" and returns the contents of the corresponding cell in column F if it is successful.

What I want to do is search for another term in column A as well as that in column B. In other words, perform two searches. Should it find an entry that is successful based on both criteria, then return the contents of the cell in column F as above.

Any help is much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To add second condition to your search replace:

=IF($B$1:$B$154="Good",ROW($B$1:$B$154)) 

With

=IF(($B$1:$B$154="Good")*($A$1:$A$154="Condition2"),ROW($B$1:$B$154))

This part:

($B$1:$B$154="Good")*($A$1:$A$154="Condition2")

Is an equivalent of:

AND($B$1:$B$154="Good",$A$1:$A$154="Condition2")

But AND often doesn't work well in array formulas (it returns single value).
Another option is to use nested IF statement.

If you are using Excel 2007 or later, you can also simplify your formula and instead of

IF(ISERROR(INDEX(...),"",INDEX(...)))

Use:

IFERROR(INDEX(...),"")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...