countif formulas and contains

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

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Countif formulas and contains criteria

Countif formulas and contains criteria

resolvedResolved · Low Priority · Version 2003

Stacy has attended:
Excel Advanced course
Access Intermediate course
Access Advanced course

Countif formulas and contains criteria

I am trying to write a =countif formula which will count anycell in a column that contains nm. The options for data entry are me, nm, nmfa, nmpa, and mb and I want to count any of the nm options (nm, nmfa, nmpa). Is there a way to write a countif formula where the criteria is anything that contains "nm" or will it have to be 3 seperate formula?

RE: Countif formulas and contains criteria

Hi Stacy

Thank you for your question

I would suggest using the dcounta function. This is a database function and requires you to create a criteria range. By simply entering all the variants of nm into this criteria range.

To create your criteria range type the heading for the column that contains your criteria and then type in the cells beneath.

You can then access the dcounta function from the paste function dialog box. It requires three arguments;

The range of the database
The Column heading of the column that contains the values that you want to count
The criteria range

I have uploaded and example which will hopefully clarify things


Regards

Stephen

Attached files...

Book1.xls

RE: Countif formulas and contains criteria

If the data is in rows, not columns, how is it done?

RE: Countif formulas and contains criteria

Hi Stacy

Thanks for the follow up

If the data is in rows then that method won't work. Before I explore other avenues could you create a transposed copy of the data?

To do this select the data and copy to clipboard. Then select the cell where you want the copied data to start. Then on the edit menu and select paste special and select the transpose option. This will then create a transposed version of your data, where rows become columns.

The method that I described above should then work

Let me know if this is not acceptable, so I can explore other angles

Regards

Stephen

RE: Countif formulas and contains criteria

A paste transpose did work, but just for my pice of mind, what if that is not possible? How would it be done?

RE: Countif formulas and contains criteria

Dear Stacy

Further to my colleague's response I would like to add that you can still use the countIF function and all you have to do is simply use these arguments:

=COUNTIF(C2:C6,"nm*")

* is the wildcard which means that it starts with nm. In your case I saw all the entries had nm at the start of the entry.

If it is in the middle or at the end then you may want to replace it with *nm*.

I hope this has answered your query.

If this has answered your query then I would request you to please mark the question as resolved!! If not and you have a specific question related to this then please post it as a new question and we should be able to provide you the solution for it!!

Kindest Regards


Rajeev Rawat
MOS Master Instructor 2000 and 2003
MCAS Master Instructor 2007
MCT

Tue 21 Apr 2009: Automatically marked as resolved.


 

Excel tip:

Convert Text to Columns in Excel 2010

If you have a cell in your Excel spreadsheet that contains a lot of text and you want to divide it into separate columns, this can only be done if there is a logical character which separates the text, for example, a comma.

Select the cells you would like to convert. On the Data tab, click Text to Columns. Choose the format of your current data.

Select Delimited if the text contains a logical character otherwise select Fixed Width if there are a certain number of spaces between each field.

Click Next when a preview of the data appears. Then select the type of character that separates the various fields. If the character is not listed, select Other and enter the character.

Click Next again and then choose the format for each of the columns. Select the column heading in the Data preview and then select a data type from the Column data format options.

Click Finish and the text will appear in several columns.

View all Excel hints and tips


Server loaded in 0.08 secs.