countif

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Countif

Countif

resolvedResolved · Medium Priority · Version 2003

Angelo has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
Access Advanced course
Access VBA course

Countif

I have two columns of data starting at A1 & B1. A1 people's age. B1 is Boolean 0 or 1 for whether or not they have a disease (0 = no, 1 = yes). I need to count the number of rows where Age < 30 and Disease = 1. The "30" and the "1" need to refer to cells so that I can change both values without having to change any code. The "<" and "=" will stay the same. Ideally, this would be part of an invented function in VBA such as =ROC(Disease,1,Age,30)= the number of people under 30 with the disease.
Thank you in advance.

RE: Countif

Hi Angelo

Thanks for your question

You can achieve the above by using a DCOUNT function. The DCOUNT is a database function. You need to create a "criteria range" with the conditions you specify, and then simply use the paste function wizard to build the function.

It has three arguments; the range of your list, the field that you wish to count and the criteria range.

You can vary the criteria by changing the values in the criteria range

I enclose a sample workbook for your information.

Regards

Stephen

Attached files...

Dcount.xls

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Create a unique items table from a duplicating table

1. Ensure that your list has column headings
2. Select the entire list
3. From the menu bar, select DATA, FILTER, ADVANCED FILTER
4. Select "Filter the list, in place", and tick the "Unique Records Only" box
5. Click OK, filtered list appears.

View all Excel hints and tips


Server loaded in 0.08 secs.