Sub topic 6
Make capitalization consistent
This chapter assumes you can already clean spaces with TRIM and write a formula over a whole column with ARRAYFORMULA. Here you will standardize the capitalization of text so that the same value is written the same way everywhere.
Why capitalization matters
Capitalization looks cosmetic, but it causes real problems when you compare, count, or export data. Whether a problem shows up depends on the tool you use. A formula that ignores case can hide inconsistencies, and a formula that respects case can break on them.
| Operation | Treats "jane" and "JANE" as the same? |
|---|---|
| `=A2=B2` | Yes, the comparison ignores case |
| `VLOOKUP`, `MATCH`, `COUNTIF` | Yes, they ignore case |
| `EXACT(A2, B2)` | No, it compares case |
| `REGEXMATCH` with a plain pattern | No, it is case-sensitive unless you add `(?i)` |
| Import into a database or another system | Depends on that system |
Most of the lookup-style functions in Sheets forgive case differences. You may therefore never see an error, and the data can still be inconsistent. The trouble appears later:
- A case-sensitive formula such as
EXACTorREGEXMATCHreports different results for rows that look like they should match. - A downstream system treats
NEW YORKandNew Yorkas two separate cities. - A report shows the same customer in three styles, which looks careless and makes sorting harder to read.
The fix is to choose one style for each column and apply it with a formula. Do this on a copy, as described in the earlier chapter on protecting the original.
The three case functions
Sheets has three functions that change case. Each takes one text value and returns a new one.
| Function | Result for `" jANE doe "` | Typical use |
|---|---|---|
| `LOWER` | `" jane doe "` | Emails, usernames, codes you compare |
| `UPPER` | `" JANE DOE "` | State codes, SKUs, country codes |
| `PROPER` | `" Jane Doe "` | Personal names, city names, titles |
None of them touches spaces. The extra spaces in the example are still there, so combine case functions with TRIM. Put TRIM on the inside so it runs first:
=PROPER(TRIM(A2))The order matters little for the final result here, but it is a good habit. The innermost function runs first, so the formula reads from the inside out: clean the spaces, then fix the case.
To apply it to the whole column in one formula, use ARRAYFORMULA:
=ARRAYFORMULA(PROPER(TRIM(A2:A)))This trims each name in column A and converts it to proper case, so " jANE doe " becomes "Jane Doe". Put the formula in the first row of an empty helper column, never on top of the source column.
Choosing a style
Pick the style from the meaning of the column, not from what is easiest.
- Use
LOWERfor values a computer will compare, such as email addresses. Lowercase is the safest common form. - Use
UPPERfor short codes with a fixed style, such asNYorUS. - Use
PROPERfor text that people read, such as names and cities.
Write the decision down in a note at the top of the sheet, so the next person applies the same rule.
Where PROPER goes wrong
LOWER and UPPER are predictable. PROPER is not, because it follows a simple rule. It capitalizes the first letter of the text and any letter that follows a character that is not a letter. It lowercases everything else. That rule produces wrong results for several common values:
| Input | `PROPER` result | Problem |
|---|---|---|
| `mcdonald` | `Mcdonald` | The second capital is lost |
| `USA` | `Usa` | Acronyms are flattened |
| `3rd floor` | `3Rd Floor` | A letter after a digit is capitalized |
| `van der berg` | `Van Der Berg` | Some surnames keep lowercase particles |
| `john smith-jones` | `John Smith-Jones` | Correct here, because a hyphen starts a new word |
You cannot fully solve these with a formula, because correct capitalization of names depends on the person. You have three practical options:
- Accept the result and fix the few exceptions by hand after the formula runs.
- Repair known patterns with
SUBSTITUTEafterPROPER. - Skip
PROPERfor columns where it does more harm than good, and useLOWERorUPPERinstead.
Here is the second option, which restores an acronym:
=ARRAYFORMULA(SUBSTITUTE(PROPER(TRIM(A2:A)), "Usa", "USA"))SUBSTITUTE is case-sensitive, so it matches Usa exactly. It would also change the start of a longer word such as Usable into USAble, so use this only on columns where the pattern cannot appear inside other words.
Check the result with EXACT
The = operator ignores case, so it cannot tell you whether a cleanup changed anything. To find out whether two values differ only by case, use EXACT, which returns TRUE only if the text matches character for character.
Suppose column A holds the raw value and column B holds the cleaned value. This formula in column C flags rows that your cleanup changed:
=ARRAYFORMULA(IF(A2:A="", "", NOT(EXACT(A2:A, B2:B))))The IF returns an empty string for blank rows, so the flag column stays clean below your data. Filter column C for TRUE to review exactly the rows that changed. This is a fast way to confirm that PROPER did not damage values you wanted to keep.
Make the cleaned values permanent
Your helper column contains formulas. If you delete the raw column, the formulas show errors, and if the raw data changes, the cleaned values change too. When you are happy with the result, turn the formulas into plain text:
- Select the helper column and copy it.
- Right-click the destination cell, and choose Paste special > Values only.
- Check a few cells to confirm they show text instead of a formula.
Paste the values into a new column or a new sheet. Keep the raw column until you finish the later checks.
Common errors
- The case did not change. The cell may hold a number or a date, not text.
UPPERleaves numbers alone, and a date stored as a date has no case to change. - Spaces are still there. The case functions do not remove spaces. Add TRIM, and if that does not work, add the CLEAN and SUBSTITUTE steps from the earlier chapter on hidden characters.
- Formula results overwrite each other.
ARRAYFORMULAfills many rows from one cell. If cells below it already contain data, the formula returns a#REF!error until you clear them. - A comparison says TRUE when you expected FALSE. The
=operator ignores case. UseEXACTwhen case is the thing you are testing.
Exercise
Cells A2:A4 contain " mARY ann ", "JOHN", and "o'brien". You enter =ARRAYFORMULA(PROPER(TRIM(A2:A4))) in B2. What does column B show? Then write a formula for C2 that returns TRUE for each row where the cleaned value in B differs from the raw value in A in any way, including case.
Show answer
Column B shows "Mary Ann", "John", and "O'Brien". The apostrophe is not a letter, so PROPER capitalizes the letter after it. For column C, use =ARRAYFORMULA(NOT(EXACT(A2:A4, B2:B4))). All three rows return TRUE, because every raw value differs from its cleaned version. A formula using = would return TRUE for "JOHN" versus "John" and miss the change, since = ignores case.
Exercise
A column of email addresses contains "[email protected]" and "[email protected]". You want one consistent form that is safe to compare. Which function do you use, and why would PROPER be a bad choice?
Show answer
Use LOWER, for example =ARRAYFORMULA(LOWER(TRIM(A2:A))). PROPER would produce "[email protected]", because it capitalizes the letter after each non-letter, including "@" and ".". That makes the address look wrong and is no more consistent than the original.