How to Use Excel IF Formula to Detect Text Codes in a Column
Question details
The user needs an Excel formula to check if a range of cells contains specific text codes (like CODE-1, CODE-2) and return 'None' if they are absent.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Data analysis and text extraction where specific formatted codes need to be identified within a column.
- Observed behavior
- The user wants to output a specific calculation or filter if codes are detected, and display 'None' when no codes are present in the specified range.
Ensure that your version of Excel supports the TEXTAFTER function, which is available in Microsoft 365 and newer versions. If using an older version, alternative functions like COUNTIF or SEARCH might be necessary.
Using IF, SUM, and TEXTAFTER Functions
This is the most efficient method for newer Excel versions to detect codes with hyphens and numeric suffixes.
This formula extracts the numeric part after a hyphen in your codes, sums the results, and checks if the total is greater than zero to determine if valid codes exist.
Click on the cell where you want the detection result to appear.
Type the formula =IF(SUM(--TEXTAFTER(C1:C36,"-"))>0,"filter","None"). Ensure you adjust the range C1:C36 to match the actual location of your data.
Replace the word "filter" in the formula with your desired calculation, text, or cell reference that should trigger when the codes are detected.
Press the Enter key to evaluate the formula and view the result.

Alternative Method: Using IF and COUNTIF with Wildcards
If you are using an older version of Excel that does not support the TEXTAFTER function, you can use COUNTIF to detect specific text patterns.
Easily Detect and Extract Text Codes using WPS Spreadsheet
WPS Spreadsheet provides powerful formula support, including advanced text manipulation and logical functions perfectly compatible with Microsoft Excel. You can seamlessly apply IF and text-extraction functions to analyze your data quickly and efficiently.
- 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your workbook containing the text codes.
- 2. Input the formula: Select an empty cell and enter your preferred detection formula, such as =IF(COUNTIF(C1:C36, "*CODE-*")>0, "Action", "None").
- 3. Evaluate the result: Press Enter to process the formula. WPS Spreadsheet will instantly calculate and display the output.
- 4. Apply across columns: Click and drag the fill handle at the bottom-right of the cell to copy the formula logic to adjacent columns if needed.

Frequently Asked Questions
Why am I getting a #NAME? error with the TEXTAFTER function?
The TEXTAFTER function is only available in Microsoft 365 and newer versions of Excel. If you see a #NAME? error, your version of Excel does not support it. You should use alternative functions like COUNTIF or a combination of SEARCH and RIGHT instead.
How can I detect multiple different codes in the same column?
You can use the COUNTIF function with an array constant to check for multiple codes simultaneously. For example, enter =IF(SUM(COUNTIF(C1:C36, {"*CODE-1*","*CODE-2*"}))>0, "Found", "None").
What does the double minus (--) do in Excel formulas?
The double unary minus (--) is used to coerce a text string that looks like a number into an actual numeric value. This is necessary because text extraction functions return text format, which mathematical functions like SUM cannot calculate directly.




