Excel IF Formula to Sum Values Only for Specific Text Like MID or LAST
Question details
The user needs to calculate the sum of specific columns only when a reference cell contains exact or partial text matches like "MID" or "LAST".

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Calculating segment offsets conditionally based on the text contents of a reference column.
- Observed behavior
- Needs a formula that outputs the sum for matching conditions or remains blank otherwise, while preventing common #VALUE! errors.
Ensure your target cells contain numerical values for summation and check whether the reference text column contains exact matches or partial strings, as this determines which formula variation you should use.
Use IF, OR, and SUM for Exact Text Matches
This is the standard method when the reference cell perfectly matches the required keywords without any extra characters.
By combining the IF, OR, and SUM functions, you can instruct the spreadsheet to evaluate whether a cell equals one of several specific text values. Using the SUM function instead of the plus operator (+) is a best practice to avoid #VALUE! errors if any referenced cells happen to contain text.
Click on cell H2 (or your preferred target output cell) where you want the conditional sum to appear.
Input the following formula: =IF(OR(A2="MID",A2="LAST"),SUM(F2:G2),""). This tells the program to sum F2 and G2 if A2 equals "MID" or "LAST", and leave it blank if neither condition is met.
Press Enter to apply the formula. Then, click and drag the fill handle (the small square at the bottom right of the cell) down to apply it to the rest of your data range.

Handle Partial Text Matches with ISNUMBER and SEARCH
Use this advanced formula if the target keywords might be embedded within other text in the cell (e.g., "Segment_MID_01").
Easily Calculate Conditional Sums with WPS Office
WPS Spreadsheet fully supports advanced logical and mathematical functions like IF, OR, SEARCH, and SUM. It provides a seamless experience for handling complex data calculations and conditional formatting.
- 1. Open your workbook: Launch WPS Spreadsheet and open the document containing your data.
- 2. Start your formula: Select the cell for your result and type =IF( to trigger the formula assistant.
- 3. Complete the syntax: Follow the on-screen formula tooltip to complete your IF, OR, and SUM syntax.
- 4. Calculate across the range: Press Enter to calculate and drag the fill handle to apply the formula across your data range.

Frequently Asked Questions
Why does my IF formula return a #VALUE! error?
A #VALUE! error often occurs if the cells you are trying to sum contain text strings or spaces instead of numbers, and you used the addition operator (F2+G2). Using the SUM function (SUM(F2:G2)) instead instructs the spreadsheet to ignore text, which prevents this error.
Is the SEARCH function case-sensitive in these formulas?
No, the SEARCH function is not case-sensitive, meaning it will match "MID", "mid", and "Mid" equally. If you require a strict case-sensitive partial match, replace the SEARCH function with the FIND function.
Can I add more conditions to the OR function?
Yes, the OR function allows multiple logical tests. You can easily add more conditions separated by commas within the OR brackets, for example: OR(A2="MID", A2="LAST", A2="FIRST").




