Formula Errors

Excel IF Formula to Sum Values Only for Specific Text Like MID or LAST

Huda QurayshiHuda Qurayshi Nov 10, 2026 870 views

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".

Excel IF Formula to Sum Values Only for MID or LAST Segments
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.
Before you start

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.

Solution 1Recommended

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.

1
Select the output cell

Click on cell H2 (or your preferred target output cell) where you want the conditional sum to appear.

2
Enter the logical formula

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.

3
Apply down the column

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.

Use IF, OR, and SUM for Exact Text Matches
Formula Applied: The cell will now display the sum only if A2 is exactly "MID" or "LAST". Otherwise, it safely returns a blank value without errors.
Master Formulas in WPS Spreadsheet

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. 1. Open your workbook: Launch WPS Spreadsheet and open the document containing your data.
  2. 2. Start your formula: Select the cell for your result and type =IF( to trigger the formula assistant.
  3. 3. Complete the syntax: Follow the on-screen formula tooltip to complete your IF, OR, and SUM syntax.
  4. 4. Calculate across the range: Press Enter to calculate and drag the fill handle to apply the formula across your data range.
Fully compatible with Microsoft Excel formulas, formats, and functionsIntuitive formula builder with syntax highlighting to prevent errorsLightweight application with fast processing for large datasetsFree to use across multiple platforms including Windows, Mac, and Mobile
microsoft office alternative - wps office

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").