You are here:

Excel/Count If Or Statement

Advertisement


Question
QUESTION: Hi Tom,
I need to create a formula that will count the cells in a range ("A1:A10") in which the cell contains either "A" or "B". Do you have any suggestions?

Thanks for the help,
Jesse

ANSWER: Jesse,

=countif(A1:A10,"A")+countif(A1:A10,"B")

or

=sum(countif(A1:A10,{"A","B"}))

--
Regards,
Tom Ogilvy


---------- FOLLOW-UP ----------

QUESTION: Thanks Tom,
As a follow up, how can I use the OR conditions in a SUMIF function?

Ex: SumIF A1:A10 = "A" OR A1:A10 = "B"

Thanks again

ANSWER: Jesse,

Your original statement

sumif(A1:A10,"A",B1:B10)+sumif(A1:A10,"B",B1:B10)

or

=SUM(SUMIF(A1:A10,{"A","B"},B1:B10))
--
Regards,
Tom Ogilvy


---------- FOLLOW-UP ----------

QUESTION: As one more follow up,
I need the Sum range (B1:B10 in the formula) to be a series of ranges.

Ex: B1:B10, C1:C10, D1:D10

How can I rewrite it to sum all three of those ranges when the OR conditions are met?

Thanks again

Answer
Jesse,

I don't believe there is a short hand method.
SUM(SUMIF(A1:A10,{"A","B"},B1:D10))   - using B1:D10 instead of B1:B10
didn't work for me so I think you have to go with:

=SUM(SUMIF(A1:A10,{"A","B"},B1:B10))+SUM(SUMIF(A1:A10,{"A","B"},C1:C10))+SUM(SUMIF(A1:A10,{"A","B"},C1:C10))


--
Regards,
Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.