Formula Errors

How to Subtract the Count of Specific Text from a Number in Excel

Amos GikundaAmos Gikunda Nov 11, 2026 869 views

Question details

The user needs a formula to count occurrences of specific text strings ('PM' and 'N') in a given range, multiply that count by 8, and subtract the final product from a starting value like 70.

How to Subtract the Count of Specific Text from a Starting Value in Excel
Product
Excel
Device & OS
not provided
Scenario
Calculating a remaining balance, score, or hours based on the occurrences of specific status codes (e.g., 'PM' or 'N') in a dataset.
Observed behavior
Requires an efficient combined formula using COUNTIF and arithmetic operations instead of calculating the counts and subtractions manually.
Before you start

Ensure your data range does not contain leading or trailing spaces around the target text strings, as this can cause the COUNTIF function to miss matching cells.

Solution 1Recommended

Use COUNTIF with an Array Constant

Use a single formula combining SUM, COUNTIF, and an array constant to efficiently count multiple text criteria and perform the subtraction at once.

This method is the most efficient because it combines multiple criteria into a single array constant. The COUNTIF function will output an array of counts for both 'PM' and 'N', which the SUM function then adds together before multiplying and subtracting.

1
Select the result cell

Click on the cell where you want the final calculated result to appear.

2
Enter the starting value reference

Begin your formula by typing the cell reference that contains your starting value (for example, A1 for the number 70) followed by a minus sign: =A1-

3
Input the COUNTIF and SUM formula

Complete the formula by entering SUM(COUNTIF(B1:N1,{"PM","N"}))*8, replacing B1:N1 with your actual data range.

4
Apply the formula

Press Enter. The full formula should look like =A1-SUM(COUNTIF(B1:N1,{"PM","N"}))*8. Excel will automatically calculate the result.

Understanding Array Constants: The curly brackets {"PM","N"} act as an array constant, telling the COUNTIF function to look for and count occurrences of both text strings simultaneously.
Use WPS Spreadsheet for Formula Calculations

Easily Calculate Advanced Formulas with WPS Office

WPS Spreadsheet offers full support for advanced array formulas, SUM, and COUNTIF functions, making it simple to perform complex data calculations and conditional counting without errors.

  1. 1. Open your workbook: Launch WPS Spreadsheet and open the file containing your text data and starting values.
  2. 2. Enter your formula: Click on the target cell and type your combined SUM and COUNTIF formula.
  3. 3. Utilize the Formulas tab: Use the 'Formulas' tab on the top ribbon to access function hints, syntax guides, and error-checking tools.
  4. 4. Calculate instantly: Press Enter to instantly calculate your conditional subtractions with precision.
Fully compatible with Microsoft Excel formulas, functions, and .xlsx file formats.Built-in formula builder to help you troubleshoot and construct complex criteria.Lightweight and fast, handling large datasets and complex conditional formatting effortlessly.Free to use across Windows, Mac, Linux, iOS, and Android devices.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my COUNTIF formula returning a 0 instead of the actual count?

This usually happens if the text in your cells has hidden spaces (like 'PM ' instead of 'PM') or if automatic calculation is turned off. Use the TRIM function to clean your data or check your calculation options in the Formulas tab.

Can I use cell references instead of typing 'PM' and 'N' inside the formula?

Yes. Instead of the array {"PM","N"}, you can reference cells containing your criteria. For example, =A1-(COUNTIF(B1:N1, X1)+COUNTIF(B1:N1, Y1))*8 where X1 and Y1 contain your targeted text strings.

Does this formula work in both Excel and WPS Spreadsheet?

Absolutely. Both Microsoft Excel and WPS Spreadsheet fully support the SUM and COUNTIF combination with array constants, ensuring seamless compatibility for your calculation workbooks.

How do I change the formula to count a third text string?

You can easily expand the array constant. To count 'PM', 'N', and 'AM', update the formula to =A1-SUM(COUNTIF(B1:N1,{"PM","N","AM"}))*8.