Using IF with Text in Excel

Most people learn the IF function through numbers first. They do something like =IF(A1>50,"pass","fail") and it works fine. Then they try to do the same thing with text values and run into issues they didn't expect. The core formula doesn't change much, but the way Excel handles text strings inside IF statements introduces a few gotchas that will waste your time if you aren't watching for them. The basic structure is straightforward. You open IF, put your condition in the first argument, what you want if it's true in the second, and what you want if it's false in the third. With text, your condition usually involves checking whether a cell equals a certain string, contains part of a string, or starts with something specific.

How the IF Function With Text In Excel Actually Works

Let's say column A has product categories like Electronics, Clothing, Food, and you want column B to show a shipping label based on what's in A. The formula in B2 would look like this: =IF(A2="Electronics","Priority",IF(A2="Food","Refrigerated","Standard")). You can nest IF statements this way. Each one checks a different condition and hands off to the next one if it doesn't match. It works until it doesn't. The first thing that trips people up is that text comparisons in Excel are case-insensitive by default. =IF(A2="electronics","Priority","Standard") will return Priority even if A2 actually says Electronics. This sounds convenient until you're auditing data and wonder why everything matches when half the entries have mixed casing. If you need case-sensitive matching, you have to pair IF with the EXACT function: =IF(EXACT(A2,"electronics"),"Priority","Standard"). That's the only built-in way to do strict text comparison. Another practical issue is leading or trailing spaces. I spent about three hours once tracking down why roughly a third of my IF statements were returning the wrong branch. The data was pulled from a legacy system that padded codes with spaces. =IF(A2="ABC123","Valid","Invalid") kept returning Invalid for cells that clearly contained ABC123. The workaround was =IF(TRIM(A2)="ABC123","Valid","Invalid"). TRIM removes those invisible spaces. Without it, you're comparing apples to apples-plus-spaces and Excel treats them as different strings.

For partial text matching, you can use ISNUMBER with FIND or SEARCH. FIND is case-sensitive, SEARCH isn't. =IF(ISNUMBER(SEARCH("sub",A2)),"Subscription","One-time") checks whether the word sub appears anywhere inside A2. SEARCH returns a position number when it finds a match, which ISNUMBER converts into a TRUE value that IF can evaluate. If SEARCH doesn't find anything, it returns an error, ISNUMBER turns that into FALSE, and IF takes the other branch. You can also check if a cell starts or ends with specific text using LEFT and RIGHT functions combined with IF. =IF(LEFT(A2,3)="NYC","East Coast","Other") looks at just the first three characters. This is useful when you're dealing with zip codes, area codes, or product SKUs where the prefix carries meaning. The same logic applies with RIGHT for suffixes. One thing beginners often miss is that IF with text doesn't auto-expand when you drag it down unless you use the fill handle correctly. Select the cell with the formula, double-click the small square at the bottom-right corner of the selection, and Excel fills the formula down to match the last row with adjacent data. If your text column has gaps, the fill stops at the first blank cell. That's not a bug, it's just how Excel works, and it costs people a lot of time when they expect automatic range detection.

Get the Full Details

IF function in Excel: formula examples for text, numbers, dates, blanks
IF function in Excel: formula examples for text, numbers, dates, blanks

Common Pitfalls and What to Do Instead

Don't wrap text strings in numeric quotes inside your formula. =IF(A2=5,"five","other") compares a text value to a number, which always returns FALSE. Excel won't warn you about this. It just gives you the wrong answer silently. Make sure both sides of your comparison are the same type. Avoid nesting more than five or six IF statements. It becomes unreadable fast, and Excel's performance degrades noticeably with deeply nested structures on large datasets. If you find yourself writing =IF(A2="A",1,IF(A2="B",2,IF(A2="C",3,IF(A2="D",4,IF(A2="E",5,0))))), switch to a lookup table with XLOOKUP or INDEX/MATCH. It's cleaner, faster, and easier to maintain when conditions change. Wildcard characters work with IF when paired with COUNTIF or COUNTIFS. =IF(COUNTIF(A2,"*term*")>0,"Contains term","No match") checks for partial matches using asterisks as wildcards. This is handy when you're filtering large ranges and need a binary true/false result without writing a separate helper column.

The biggest limitation of IF with text is that it only evaluates one condition per branch unless you nest further. It doesn't natively support OR or AND logic the way newer functions like IFS or SWITCH do. If you need to check multiple text conditions at once, use AND or OR inside the IF: =IF(AND(LEFT(A2,2)="NY",RIGHT(A2,1)="A"),"East","Other"). This keeps it in a single formula but adds complexity quickly. Excel also doesn't handle unicode or special characters well in text comparisons. If your dataset includes accented characters or non-Latin scripts, case-insensitive matching can behave unpredictably. I ran into this with a client who had French product names with accents like été and café. =IF(A2="été","Accent Match","No Match") failed because the cell contained a visually identical but byte-different version of the word. The fix was normalizing both sides with the UNICODE and SUBSTITUTE functions, though honestly that level of troubleshooting only comes up in data-poor environments where cleaning happens at import time rather than in the formula layer. If your workbook is going to be shared across regions with different Excel language versions, be aware that function names change. IF is universal, but IFERROR and XLOOKUP may not be available depending on your version. Stick to IF, IFERROR, and basic string functions for maximum compatibility if you don't control the environment.