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
710 views
in Technique[技术] by (71.8m points)

excel - SUMIF with OR criteria

How to use SUMIF formula in Excel cell that must sum over a given range and instead of finding for a single value, it should find multiple values?

For finding a single value, I use:

=SUMIF(A4:A100;"1";B4:B100)

Now I need to sum over if the column A holds 1 or 2, like:

=SUMIF(A4:A100;"1" OR "2";B4:B100)

The cell A1 will hold the criteria as a text, here it would be 1;2.

It should return same as

=SUMIF(A4:A100;"1";B4:B100) + SUMIF(A4:A100;"2";B4:B100)

but I need a formula that can take any number of criteria (1,2,3,... or more).

What's the syntax? I'm not able to use VBA here.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

To sum for 1 or 2 try this version

=SUM(SUMIF(A4:A100;{1;2};B4:B100))

SUMIF will return an "array" of two results so you need SUM to sum that array for the total for 1 and 2

You can add as many numbers as you like e,g,

=SUM(SUMIF(A4:A100;{1;2;3;4};B4:B100))

or with numbers listed in a range like Z1:Z10

=SUMPRODUCT(SUMIF(A4:A100;Z1:Z10;B4:B100))


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

...