30 Advanced Excel Tips for 2026

Excel Champs / Excel Formulas List / Sum IF Cell Contains a Specific Text (SUMIF Partial Text)
By Puneet Gogia (Microsoft MVP)

Sum IF Cell Contains a Specific Text (SUMIF Partial Text)

30+ Advanced Excel Tips for 2026

No spam. Only Excel Stuff. God Promise. 😊

To sum values where a cell contains specific text, wrap the text in asterisks inside SUMIF’s criteria: =SUMIF(A2:A10,"*Mobile*",B2:B10). The * wildcard tells Excel to ignore whatever comes before or after the word, so it matches “Mobile Cover” and “Samsung Mobile” alike.

To pull the text from a cell instead of typing it in, join it with & — =SUMIF(A2:A10,"*"&D1&"*",B2:B10). SUMIF is not case-sensitive, so “mobile” and “MOBILE” are both counted. For more than one condition, use SUMIFS: =SUMIFS(B2:B10,A2:A10,"*Mobile*",C2:C10,"North").

To sum values from cells where you have a specific text or a partial text, you need to use wildcard characters with SUMIF. In the criteria argument, you need to use an asterisk before and after the text using an ampersand, just like we have used in the following example to sum cells where you have the text “Mobile” in the “Product” column.

sumif-partial-text

In this tutorial, you will learn to write this formula by using SUMIF.

Formula to Sum IF Cell Contains a Specific Text

  1. First, in cell C1, enter “=SUMIF(“.
  2. Next, refer to the range you need to check for the criteria.
  3. Now, in the criteria, enter an asterisk-criteria-asterisk (“*”&”Mobile”&”*”).
  4. Next, in the sum_range argument, refer to the quantity column.
  5. In the end, hit Enter to get the result.
sumif-reference
=SUMIF(A2:A10,"*"&"Mobile"&"*",B2:B10)
understand-sumif-contains-text-formula

The formula looks at each cell in the range A2:A10 and checks whether the word “Mobile” appears anywhere in each cell. The “*” wildcard character on both sides of “Mobile” tells Excel to ignore what comes before or after it, which makes it a partial text match. SUMIF with wildcards isn’t case-sensitive, so it also matches “MOBILE” and “mobile”. Also, SUMIFS can be used if you have multiple conditions.

=SUMIFS(sum_range, criteria_range1, "*text*")

You can also write the text inside the asterisks directly, or join the asterisks to a cell, so you can change the text without editing the formula (D1 has the text to look for):

=SUMIF(A2:A10,"*Mobile*",B2:B10)
=SUMIF(A2:A10,"*"&D1&"*",B2:B10)

And here’s SUMIFS with a second condition: it sums the values over 20 where the product contains “Mobile”.

=SUMIFS(B2:B10,A2:A10,"*Mobile*",B2:B10,">20")

One thing to keep in mind: in Excel, wildcards only work with text. If the column has numbers (like product codes stored as numbers), “*23*” won’t match them. In that case, use SEARCH with SUMPRODUCT, which works with both text and numbers:

=SUMPRODUCT(ISNUMBER(SEARCH("23",A2:A10))*B2:B10)

Sum IF a Cell Contains Partial Text using Case-Sensitive Match

If you want to sum values based on a case-sensitive search, use an array formula combining FIND, IF, and SUM. In Excel 2019 and older, this formula needs to be entered as an array formula to handle case-sensitive partial-text matches.

=SUM(IF(ISNUMBER(FIND("MOBILE", A2:A10)), B2:B10, 0))

Note: For this formula to work as an array formula in some versions of Excel, you need to enter it with Ctrl+Shift+Enter.

This formula sums values from column B, but only for rows in column A that contain “MOBILE” in uppercase (anywhere in the text).

Here’s how it works: The formula goes through each cell in the range A2:A10 and uses the FIND function, which is case-sensitive, to look for the value “MOBILE”.

If FIND finds “MOBILE”, it returns a number indicating where “MOBILE” starts in the text. The ISNUMBER function checks if FIND returned a number (meaning “MOBILE” was found). If it did find “MOBILE”, the corresponding value from column B is included in the sum.

If “MOBILE” wasn’t found, or if it’s in a different case (like “Mobile” or “mobile”), it adds zero instead for that row. This way, the formula only adds up the numbers from column B where “MOBILE” matches, with the same case, in column A.

If you don’t want to use an array formula, SUMPRODUCT gives the same result with a normal Enter:

=SUMPRODUCT(ISNUMBER(FIND("MOBILE",A2:A10))*B2:B10)

FILTER, used in the next section, is available in Microsoft 365 and Excel 2021 and later.

Use Dynamic Functions to Sum Values on a Partial Text

You can also use Excel’s dynamic array functions to sum based on partial text. FILTER works in Microsoft 365 and Excel 2021 or later, and BYROW and LAMBDA need Microsoft 365 or Excel 2024.

Let’s say column A contains product names, and column B contains corresponding sales figures. You want to sum all sales values where the product name contains “Mobile”:

=SUM(FILTER(B:B, ISNUMBER(SEARCH("Mobile", A:A))))

This formula sums up values from column B, but only for rows where the word “Mobile” is found in column A.

It searches for “Mobile” in each cell of column A and, if found, adds the corresponding value from column B to the total. SEARCH isn’t case-sensitive; use FIND instead if you need a case-sensitive match.

But if no cells meet the criteria, FILTER returns the #CALC! error, which you can handle with IFERROR:

=IFERROR(SUM(FILTER(B:B, ISNUMBER(SEARCH("Mobile", A:A)))),0)

Or you can use BYROW in combination with SEARCH.

=SUM(BYROW(A:A, LAMBDA(cell, IF(ISNUMBER(SEARCH("Mobile", cell)), INDEX(B:B, ROW(cell)), 0))))

This formula checks column A for the word “Mobile”. If the word “Mobile” is found in a row, the formula looks at the corresponding row in column B and takes that sales value. If the text “Mobile” is not found, it takes zero instead. In the end, SUM adds up all the numbers that were picked from column B. As BYROW goes through every row of column A, this formula can be slow on a big sheet; use a range like A2:A1000 instead of A:A to speed it up.

Use a Custom Function to SUM Values Based on a Partial Text

And if you’d like to use a custom function for this, here’s a VBA function that performs a case-insensitive sum based on a partial text match:

Function iSUMIFCONTAINS(searchRange As Range, searchText As String, sumRange As Range) As Variant
    Dim cell As Range
    Dim sumResult As Double

    ' Initialize the result variable.
    sumResult = 0

    ' Check if both ranges are of the same size
    If searchRange.Rows.Count <> sumRange.Rows.Count Or searchRange.Columns.Count <> sumRange.Columns.Count Then
        iSUMIFCONTAINS = CVErr(xlErrRef)
        Exit Function
    End If

    ' Loop through all cells in the searchRange
    For Each cell In searchRange
        If InStr(1, cell.Value, searchText, vbTextCompare) > 0 Then
            ' If searchText is found, add the corresponding value from sumRange
            sumResult = sumResult + sumRange.Cells(cell.Row - searchRange.Row + 1, cell.Column - searchRange.Column + 1).Value
        End If
    Next cell

    ' Return the result
    iSUMIFCONTAINS = sumResult
End Function

Press Alt + F11 to open the VBA editor. In the VBA editor, right-click on any object in your Project Explorer. Then, choose Insert > Module. This action creates a new module. Paste the code into the newly created module.

Now, you can use this new function: iSUMIFCONTAINS

=iSUMIFCONTAINS(A2:A10,"Mobile",B2:B10)

And if you want to do a sum for partial text based on case sensitivity, use the following version. It has the same name, so replace the first function with it (two functions with the same name in one module give the “Ambiguous name detected” error). Leave out the last argument, or set it to FALSE, for a case-insensitive match:

Function iSUMIFCONTAINS(searchRange As Range, searchText As String, sumRange As Range, Optional caseSensitive As Boolean = False) As Variant
    Dim cell As Range
    Dim sumResult As Double
    Dim compareMode As Integer

    ' Determine comparison mode based on case sensitivity option
    If caseSensitive Then
        compareMode = vbBinaryCompare   ' Case-sensitive
    Else
        compareMode = vbTextCompare     ' Case-insensitive
    End If

    ' Initialize the result variable.
    sumResult = 0

    ' Check if both ranges are of the same size
    If searchRange.Rows.Count <> sumRange.Rows.Count Or searchRange.Columns.Count <> sumRange.Columns.Count Then
        iSUMIFCONTAINS = CVErr(xlErrRef)
        Exit Function
    End If

    ' Loop through all cells in the searchRange
    For Each cell In searchRange
        If InStr(1, cell.Value, searchText, compareMode) > 0 Then
            ' If searchText is found, add the corresponding value from sumRange
            sumResult = sumResult + sumRange.Cells(cell.Row - searchRange.Row + 1, cell.Column - searchRange.Column + 1).Value
        End If
    Next cell

    ' Return the result
    iSUMIFCONTAINS = sumResult
End Function
=iSUMIFCONTAINS(A2:A10,"MOBILE",B2:B10,TRUE)

Both functions return the #REF! error when the two ranges aren’t the same size. Save the workbook as a macro-enabled file (.xlsm) to keep the function.

Frequently Asked Questions

Is SUMIF with wildcards case-sensitive?

No. “*Mobile*” matches “Mobile”, “MOBILE” and “mobile”. For a case-sensitive sum, use FIND with SUMPRODUCT or the array formula shown above.

How do I sum if a cell contains one of several words?

Use SUMIF with an array of criteria inside SUM. The formula below sums the rows that contain “Mobile” or “Tablet”. If one cell can contain both words, it’s counted twice, so use the SUMPRODUCT version with SEARCH in that case.

=SUM(SUMIF(A2:A10,{"*Mobile*","*Tablet*"},B2:B10))

How do I search for an asterisk or question mark?

Put a tilde (~) before it, so Excel treats it as a normal character, like “*~?*” to sum the rows that contain a question mark.

Puneet Gogia

Written by

Puneet Gogia

Microsoft MVP — Excel · Founder, Excel Champs

Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.

3M+ readers helped
1,000+ tutorials written
Since 2015 teaching Excel

3 thoughts on “Sum IF Cell Contains a Specific Text (SUMIF Partial Text)”

  1. Great post! I’ve been looking for a way to sum up values based on partial text matches in my spreadsheets, and your explanation of the SUMIF function really clarified things for me. The examples were super helpful too. Thanks for sharing!

    Reply
  2. This post really helped me understand how to use the SUMIF function with partial text

    Reply
  3. This post was incredibly helpful! I often struggle with functions in Excel, but your clear explanation of the SUMIF function with partial text made it so easy to follow. I can’t wait to try it out in my own spreadsheets. Thank you for sharing!

    Reply

Leave a Comment