In our previous tutorial, we were looking at Excel If contains formulas that return some value to another column if a target cell contains a given value. Aside from that, what else can you do if a cell contains specific text or number? A variety of things such as counting or summing cells, highlighting, removing or copying entire rows, and more.

In Microsoft Excel, there are two functions to count cells based on their values, COUNTIF and COUNTIFS. These functions cover most, though not all, scenarios. The below examples will teach you how to choose an appropriate Count if cell contains formula for your particular task.

In situations when you want to count cells containing any text, use the asterisk wildcard character as the criteria in your COUNTIF formula:

COUNTIF(*range*,"*")

Or, use the SUMPRODUCT function in combination with ISTEXT:

SUMPRODUCT(--(ISTEX(*range*)))

In the second formula, the ISTEXT function evaluates each cell in the specified range and returns an array of TRUE (text) and FALSE (not text) values; the double unary operator (--) coerces TRUE and FALSE into 1's and 0's; and SUMPRODUCT adds up the numbers.

As shown in the screenshot below, both formulas yield the same result:

`=COUNTIF(A2:A10,"*")`

`=SUMPRODUCT(--(ISTEXT(A2:A10)))`

To count cells that contain specific text, use a simple COUNTIF formula like shown below, where *range* is the cells to check and *text* is the text string to search for or a reference to the cell containing the text string.

COUNTIF(*range*,"*text*")

For example, to count cells in the range A2:A10 that contain the word "dress", use this formula:

`=COUNTIF(A2:A10, "dress")`

Or the one shown in the screenshot:

To count cells that contain a certain substring, use the COUNTIF function with the asterisk wildcard character (*).

For example, to count how many cells in column A contain "dress" as part of their contents, use this formula:

`=COUNTIF(A2:A10,"*dress*")`

Or, type the desired text in some cell and concatenate that cell with the wildcard characters:

`=COUNTIF(A2:A10,"*"&D1&"*")`

For more information, please see: COUNTIF formulas with partial match.

To count cells with multiple conditions, use the COUNTIFS function. Excel COUNTIFS can handle up to 127 range/criteria pairs, and only cells that meet all of the specified conditions will be counted.

For example, to find out how many cells in column A contain "dress" AND "blue", use one of the following formulas:

`=COUNTIFS(A2:A10,"*dress*", A2:A10,"*blue*")`

Or

`=COUNTIFS(A2:A10,"*"&D1&"*", A2:A10,"*"&D2&"*")`

The formula to count cells with numbers is the simplest formula one could imagine:

COUNT(*range*)

Please keep in mind that the COUNT function in Excel counts cells containing any numeric value including numbers, dates and times, because in terms of Excel the last two are also numbers.

In our case, the formula goes as follows:

`=COUNT(A2:A10)`

To count cells that DO NOT contain numbers, use the SUMPRODUCT function together with ISNUMBER and NOT:

`=SUMPRODUCT(--NOT(ISNUMBER(A2:A10)))`

If you are looking for an Excel formula to find cells containing specific text and sum the corresponding values in another column, use the SUMIF function.

For example, to find out how many dresses are in stock, use this formula:

`=SUMIF(A2:A10,"*dress*",B2:B10)`

Where A2:A10 are the text values to check and B2:B10 are the numbers to sum.

Or, put the substring of interest in some cell (E1), and reference that cell in your formula, as shown in the screenshot below:

To **sum with multiple criteria**, use the SUMIFS function.

For instance, to find out how many blue dresses are available, go with this formula:

`=SUMIFS(B2:B10, A2:A10,"*dress*",A2:A10,"*blue*")`

Or use this one:

`=SUMIFS(B2:B10, A2:A10,"*"&E1&"*",A2:A10,"*"&E2&"*")`

Where A2:A10 are the cells to check and B2:B10 are the cells to sum.

In our last tutorial, we discussed three different formulas to test multiple conditions and return different values depending on the results of those tests. And now, let's see how you can perform different calculations depending on the value in a target cell.

Supposing you have sales numbers in column B and want to calculate bonuses based on those numbers: if a sale is over $300, the bonus is 10%; for sales between $201 and $300 the bonus is 7%; for sales between $101 and $200 the bonus is 5%, and no bonus for under $100 sales.

To have it done, simply multiply the sales (B2) by a corresponding percentage. How do you know which percentage to multiply by? By testing different conditions with nested IFs:

`=B2*IF(B2>=300,10%, IF(B2>=200,7%, IF(B2>=100,5%,0)))`

In real-life worksheets, it may be more convenient to input percentages in separate cells and reference those cells in your formula:

`=B2*IF(B2>=300,$F$5,IF(B2>=200,$F$4,IF(B2>=100,$F$3,$F$2)))`

The key thing is fixing the bonus cells' references with the $ sign to prevent them from changing when you copy the formula down the column.

If you want to **highlight** cells with certain text, set up an Excel conditional formatting rule based on one of the following formulas.

SEARCH("*text*", *topmost_cell*)>0

FIND("*text*", *topmost_cell*)>0

For example, to highlight SKUs that contain the words "dress", make a conditional formatting rule with the below formula and apply it to as many cells in column A as you need beginning with cell A2:

`=SEARCH("dress", A2)>0`

To highlight cells that contain two or more text strings, nest several Search functions within an AND formula. For example, to highlight "blue dress" cells, create a rule based on this formula:

`=AND(SEARCH("dress", A2)>0, SEARCH("blue", A2)>0)`

For the detailed steps, please see How to create a conditional formatting rule with a formula.

In case you want to delete rows containing specific text, use Excel's Find and Replace feature in this way:

- Select all cells you want to check.
- Press Ctrl + F to open the
*Find and Replace*dialog box. - In the
*Find what*box, type the text or number you are looking for, and click the*Find All* - Click on any search result, and then press Ctrl + A to select all.
- Click the
*Close*button to close the*Find and Replace* - Press Ctrl and the minus button at the same time (Ctrl -), which is the Excel shortcut for Delete.
- In the
*Delete*dialog box, select*Entire row*, and click OK. Done!

In the screenshot below, we are deleting rows containing "dress":

In situations when you want to select or copy rows with relevant data, use Excel's AutoFilter to filter such rows. After that, press Ctrl + A to select the filtered data, Ctrl+C to copy it, and Ctrl+V to paste the data to another location.

To filter cells with two or more criteria, use Advanced Filter to find such cells, and then copy the entire rows with the results or extract only specific columns.

For the detailed step-by-step instructions, please see the following tutorials:

- Excel AutoFilter: How to copy filtered data
- Advanced Filter: How to extract only specific columns
- Advanced Filter: How to copy filtered data to another worksheet

This is how you manipulate cells based on their value in Excel. To have a closer look at the formulas discussed in this tutorial, you are welcome to download our sample Excel If Cell Contains workbook. I thank you for reading and hope to see you on our blog next week!

Excel formulas
CSV
Excel functions
Print
Vlookup
Merge data in Excel
SumIf
CountIf
Excel Compare
If statement
Excel Charts
Pivot Table
Updates
Conditional formatting
Excel formatting
Excel time
Excel duplicates
Excel date
Excel tips
Excel macro
Outlook
Google Sheets
Outlook duplicates
Outlook templates

## 43 Responses to "Excel: If cell contains then count, sum, highlight, copy or delete"

How To Highlight Row If Cell Contains Text/Value/Blank In Excel

I would like to highlight Equal no. of cells to the numeric value in some cell. i.e

if i put 5 in cell no. A1, then cell B1,C1,D1,E1,F1 Shall be filled in red colour...

how to do it pls help

Krishna Das:

Sorry, I think the only way to do what you want is by writing some VBA code. That's beyond the scope of this blog.

How would I sum a filtered columns visible data by using another columns text, I need the below formula to count visible cells of a filtered column based on a word

=COUNTIF(A2:A10,"*dress*")

Sorry, More specific. Same question

=SUMIF(E18:E4020,"Immediately",$D18:$D4020)/E2

Trying to get the above formula to sum Visible cells in column D, currently it sums all cells

Column E contains text,"Immediately" is one of the choices.

Column D contains numeric values that need to be summed

based on the choice of the word "Immediately"

They are filtered.

Phil:

Svetlana has a very thorough article here on AbleBits that covers this topic.

Enter "sum only filtered (visible) cells" in the search box and you'll see the link to the article.

Thanks for responding Doug, but nothing there is helping this particular scenario.

=SUM(COUNTIFS(TAB!$H:$H,{"chips","ice cream"},TAB!$E:$E,">1/1/18",TAB!$E:$E,"<2/1/18"))

I am trying to modify this formula so that once the criteria is met, that all the numbers found in column U are added together. I can't seem to figure how to get this to work out. Please help.

Hello,

how to do if the cell is a date, say: 1/1/2018, then to sum a row of numbers and add another number in a cell, e.g. a2:j2, +e20. If it is not the date (1/1/2018), then let it be blanked...

thank you.

I’d like to use a sumifs type formula, but instead of summing numbers, I’d like to grab text (vlookup won’t work because I need to use multiple criteria). Any ideas?

I would like to select only cell with numerical value from row containing numerical and non-numerical value.

What Excel function and how to use if I select a word in cell (with drop down list with few text) and I would like each selected text to return a different drop down list from different sheet?

I was hoping you could help me with a formula.

I would like to calculate a range cells in a row if text is "Something"

so:

2.5 PM

2 CE

2.5CE

2 IPT

3.5 PM

I was hoping you could help me with a formula.

I would like to calculate a range cells in a row if text is "Something"

so:

A1 A2 B4:

2.5 PM 6.0 This pulls all the values from A1 that have PM in A2.

2 CE

2.5 CE

2 IPT

3.5 PM

Daniel:

You will use the SUMIF function including the optional sum_range. Where the data is in columns J, K and L enter this in L2:

=SUMIF(K2:K5,"PM",J2:J5)

You're saying, "Sum the values in J2 thru J5 where the text in the adjacent cells K2 thru K5 is PM." So, it's range, criteria, sum_range.

I need to do something along the lines of "If cell contains text "ab" then perform calculation (D10-0.15)-120)" basically I need the number showing in that cell to either be calculated using one formula or another..... not sure how to structure this or if it's possible. Thanks in advance!

A cell contains =IF(ISNUMBER(SEARCH("Avox Production",B60)),"1","")

The statement enters a "1" in the cell when the word "Avox Production" is typed in another cell B60.

I have a range of cells with the statement listed above. What I need to do is gather the sum of all cells with "1" and populate the total of these cells into another worksheet.

I've tried =SUM(B60:B65,Data!B60:B65) but nothing populates in the cell.

What is the cell address for the cell containing the formula:

=IF(ISNUMBER(SEARCH("Avox Production",B60)),"1","")

That cell address will contain the "1" or ""

Sum that column to get your values

How about if i have a column of numbers and i want to search for matching numbers that then contain text in another column that i want to highlight mismatched PART text string. i.e

A1 B1

1 1562544 Engine

2 1562544 Cam Shaft

3 1573333 Engine 2

4 1573333 Engine 2

5 1582444 Engine

6 1582444 Engine

7 1582444 Cam Shaft Fixing

8 1628738 Cam Shaft

9 1628738 Cam Shaft - Chrome

I would only want a return for the rows that contain conflicting information i.e 1562544 and 1582444 in this case, i do not mind if it is just rows 2 & 7 that are returned or all that mismatch i.e 1&2 and 5,6&7 . Worth noting that rows 8&9 i do not consider a mismatch (hence the need for a PART string match)

Hope that makes sense

All Example and conversation are helpful,but if u add language option in your web side so its so easy and convenient for me and others, and I think Its plus point about you..

kind regards

sarmad azim

I'm working on a spreadsheet where i would like for a formula to be created when any text is entered into the cell to the left. If you enter a company name in a cell it will then create a PO based off the job number (in one cell) & the cost code (another cell)

Cell B2 is My Job Number & Cell A14 is My Cost Code. =B2&-A15 give me a my PO (Job Number-Cost Code). Now i would like this to be created only when text is entered in the cell to the left.

I am trying to see if excel can search a column and automatically add up specific cells to come as close to without exceeding a specific number. Example: I have a 12' (120") piece of lumber and I need to cut that into as many posts as possible with little waste. So in the example below it would highlight cells (A1, A2, A5, A6) in a specific color, then in another color continue with the other cells (not previously selected) and perform the same function. Thanks for any help.

A1 13.5"

A2 25.75"

A3 54"

A4 32"

A5 16"

A6 64.75"

A7 10"

A8 12.5"

A9 11

C5=Q

D5=Q

E5=H

F5=H

G5=Q

H5=Q

I5=H

J5=Q

K5=H

L5=H

M5=H

N5=H

O5=Q

P5=Q

Q is the travel plan for onsite. for the above example its 7 weeks stays.

but the onsite trip would be 4. so i need to caluclate the trip count.

I want to have a successive cell count where the value is "Q"

For the above example it would be 4.

Thanks

Srini

Trying to make a formula where if a cell has the text "GMP 1" then show the value which is in the same row but from column A. Also this has to work over separate sheets.

So, for example, i need it to look through column C on sheet 1 for the word "GMP 1" but return the row value of Column A, and put the result on sheet 2. Currently i have multiple efforts at the formula and getting results where it adds up the values from A (which i dont want) or #value #n/a or just the count value of if it is true. Tried multiple different starting points (sumproducts/vlookup etc)

Did anyone ever answer you? I'm looking for the same solution and can't figure it out for the life of me. Thanks!

Any Help Apprecaiated:

Essentially I am trying to write a formula where if all cells in a column range contain a numerical value it will SUM them, but add a condition where if the column contains a text it will search for the text and instead of returning a SUM it will return "Not Complete".

Currently I am working with the following formula but cant seem to get it to work:

=IF(ISNUMBER(SEARCH("Not Complete",H4:$H2000)),"Not Complete",SUM(H4:$H2000))

For Reference:

Column of values mixed with text containing "Not Complete"

$0.052000

$0.052000

$0.052000

$0.052000

Not Complete

Not Complete

Not Complete

Not Complete

$0.052000

$0.052000

$0.052000

Hi,

Is there a solution for this?

Basically, I have month in one column and dollars in another. If I want the sum of all the dollars in June, July and Aaugust in a separate column. Is there a formula that does this. I am sure there is but cannot figure it out.

Thanks,

Dinesh.

Month dollar sum

June 20

June 30

June 25

June 22

June 31 sum of June dollars

July 18

July 16

July 15

July 22

July 19 sum of July dollars

August 6

August 3

August 32

August 34

August 24 sum of Aug dollars

I need a formula that will search a specific cell (E2) or all of column E for a "key" word and then if found, take the date in A2 and add 30 days to it and put this all in B2.

Please let me know if this can be accomplished.

Thanks.

Hello,

Did you find a solution for your issue? I am currently trying to find something similar. I need to find all people who are online and add their hours, ignoring those who are on leave etc, Can anyone help?

Thanks in advance

How do I have a cell calculate a sum if there's a certain word or text in another cell? I.E. 12345*2% will only be calculated if say cell A5 was showing the word "No".

Thanks!

Thank you so much for most helpful forumula

How can I delete upon scanning a bar code, everything except the text that starts with UL9C0037365 value in a cell

01008568230065341119071521UL9C0037365

Thank you

george

Hello George!

In order to extract all the characters after "UL9", use the formula below:

=RIGHT(A10, LEN(A1) - FIND("UL9", A1,1) +1)

As for pulling the text before "UL9", here is the formula for this case:

=LEFT(A1, FIND("UL9", A1 ,1) - 1)

BTW, there is a formula-free solution for this task called Extract Text tool. Check out its manual, I believe you'll find it helpful: https://www.ablebits.com/docs/excel-extract-text/

Please if cell b4 has a data of 24pcs and cell c4 has 34000....

I want to multiply the two cell together...

Please how can I go about this.

Thanks

Hello Gbenga!

If I understand your task correctly, the following formula should work for you

=LEFT(A1,LEN(A1) - FIND("pcs",A1)) * B1

Hope you’ll find this information helpful.

Hi there,

How do I Sum out multiple SKUs when I keyed them in according to the warehouse racking layout?

Example :

A1 B1 C1 are the name of the SKUs, while A1 C1 has the same SKU.

A2 B2 C2 will be the Quantity of each SKU above.

How do I get the the sum of A2 and C2 in a separate list if we got 600 SKUs.

Thank you.

I am looking to use a condition on one cell (A2=Kabul, then pick data from another sheet, K5) and the same condition will be repeated in one formula (A2=Laghman, A2=Logar..... and then data will be picked from a different cell). How I can do it?

Hello Ebadullah!

I’m sorry but your task is not entirely clear to me.

For me to be able to help you better, please describe your task in more detail. Please let me know in more detail what you were trying to find, what formula you used and what problem or error occurred. Give an example of the source data and the expected result. It’ll help me understand it better and find a solution for you. Thank you.

Hello, could you please help me to find formula that highlights the cell with specific text when the text is a list? Is this the correct way to do it in Conditional Formatting (by formula)?

=ISNUMBER(MATCH($A$2,List,0))

when list is the range of list cells?

If this is the best way, Is there a way to copy this exact formatting to other cells (format painter doesn't do the job)?

Thank you so much in advance.

Hello Ludmila!

If I understand your task correctly, the following conditional formatting formula should work for you:

=ISNUMBER(MATCH($A$2,F2,0))

where F2 is the first cell of the list cell range.

I hope it’ll be helpful.

Hello Alexander, thank you for your answer. Unfortunately, the formula you've suggested didn't work for me, though the formula that includes range of cells containing the list works well.

My additional question was is there a way to apply the same conditional formatting formula to multiple cells. I mean is there a fast way to copy the conditional formatting formula that will be updated to other cells (eg A3, A4 and so on) instead of creating a new rule for every next cell? Thank you!

Hello!

I'm sorry the formula wasn't useful to you. Apparently, we represent your data differently.

How to copy conditional formatting is described here.

Thank you for all the Information they are great. what i would like to dois:

I Have in column A a data validation that has X,Y Z and on a different sheet under X i have a list of names in a column as well as under Y ans Z. what I want, is when I choose for example X in column A, I want in column B automatically to copy all the names of the other sheet under X into the cells in column B into a column not row? please can you help me with this problem?