1. Lighthouse

Level 2 · Fix spaces and casing in city and state

The request

From Helen Parker, Support Specialist

“The winter catalog goes to Texas customers who signed up since September. Last time the labels printed ' austin ' and 'tx' and the print shop called us. Can you give me clean city and state columns, and mark the rows you changed so I can spot-check them?”

Your goal

In F2:F49, the city from column D with spaces trimmed and each word capitalised. In G2:G49, the state from column E trimmed and in capitals. In H2:H49, TRUE when the cleaned city or state differs from the raw value in any way, case included (use EXACT). In J1, count the changed rows.

  • Fill F2:H49, J1 with the right valuesnot done yet
  • With formulas, not typed numbersnot done yet
  • Use TRIM PROPER UPPER EXACTnot done yet

Your sheet

Excel
The sheet for this level
ABCDEFGHIJK
1customer_idfirst_namelast_namecitystateclean_cityclean_statechangedRows changed
21612KarenFisherHoustonTX
31617LucasMonroeSan AntonioTX
41627ValeriaGallagherDallasTX
51636PatriciaGarciaDallasTX
61640ChristineMartinezHoustonTX
71642EricMooreSan AntonioTX
81643DonaldTurnerhoustonTX
91649TimothyBrownHoustonTX
101653JacobWatsonAustinTX
111663WilliamLewisDallasTX
121677AndrewRussellHoustonTX
131678BettyBennettSan AntonioTX
141680JanetBennettHoustonTX
151682NicoleTurnerDallasTX
161683LindaKingHoustonTX
171688MarcusTorresHoustonTX
181703DylanPerryDallasTX
191718EdwardJamesDallasTX
201726MeiVasquezHoustonTX
211743ChloeRamosDallasTX
221760PeterMitchellAustintx
231763KathleenHillHoustonTX
241772JenniferRussellHoustonTX
251789KyleMillerHoustonTX
261799SofiaCruzAustinTX
271801KatherineGarciaHOUSTONTX
281804KyleAdamsSan AntonioTX
291811TimothyEdwardsAustinTX
301816MichelleGrahamSan AntonioTX
311820ChristineMoralesDallasTX
321845DebraRamirezHoustonTX
331867JeffreyBakerSan AntonioTX
341870SarahDavisHoustonTX
351871RonaldHayesDallasTX
361888DonaldGomez austin TX
371900ChristopherTaylorHoustontx
381910PatrickWhiteHoustonTX
391929MaryMoralesHoustonTX
401935LoganYoungDallasTX
411945LoganKimDallasTX
421953PatrickBarnesSan AntonioTX
431957ShirleyGomezHouston TX
441963SofiaWardHoustonTX
451966KarenJamesDallasTX
461969DonaldJacksonDallasTX
471978JerryWhiteSan AntonioTX
481987LuisHillDallasTX
491993LoganHarrisonHoustonTX
50
51

Loading the editor…

    ResultPress Check to compare F2:H49, J1

    Mote checks your result

    Press Check. Each right cell becomes a firefly in your lantern.

    The lesson

    Text that looks the same is not always the same. 'Houston ' has a trailing space you can’t see in a cell. 'houston' and 'HOUSTON' look sloppy on a label and split one city into three in a pivot or a chart. This sheet holds Texas customers who signed up since September 2025, straight from the customer export, mess included.

    Three cleaning functions

    Function Does D36 = ' austin ' becomes
    TRIM(text) removes spaces at both ends, squeezes runs of spaces inside to one 'austin'
    PROPER(text) capital first letter of each word, the rest lower case ' Austin '
    UPPER(text) / LOWER(text) everything upper / lower case ' AUSTIN '

    They combine from the inside out. For the city:

    F2   =PROPER(TRIM(D2))

    and for the state, which is a two-letter code:

    G2   =UPPER(TRIM(E2))

    E16 holds 'TX ' with a trailing space; G16 becomes TX. D27 holds HOUSTON; F27 becomes Houston.

    Where PROPER goes wrong

    PROPER capitalises after anything that isn’t a letter, which is right for San Antonio and St. Louis and wrong for some names: PROPER("mcallen") gives Mcallen, and PROPER("o'brien") gives O'Brien (right) but PROPER("it's") gives It'S. All the cities here survive it. Before you run it over a column of surnames or brand names, scan the result.

    Proving what changed: EXACT, not <>

    Helen wants the changed rows marked. The obvious test is =D2<>F2. It fails quietly: Excel compares text without looking at case, so "houston"<>"Houston" is FALSE. Written as =OR(D2<>F2,E2<>G2), the flag catches the four rows with stray spaces (16, 25, 36 and 43) and misses rows 8, 22, 27 and 37, where only the case changed.

    EXACT(text1, text2) compares character by character, case included, and returns TRUE only for an identical match. A row is unchanged when both columns match exactly, so the flag is the opposite of that:

    H2   =NOT(AND(EXACT(D2,F2),EXACT(E2,G2)))

    J1 counts the TRUEs with =COUNTIF(H2:H49,TRUE): 8 of the 48 rows. Helen checks those eight labels and trusts the rest.

    Keep the raw column

    Never clean a column in place. Keep city as exported and put clean_city next to it. If a rule turns out wrong (a PROPER that mangled a name, say), you fix one formula and everything updates. When the sheet goes to the print shop, copy the clean columns and paste them as values into a new file.

    For a variant that no function can fix, like a misspelling (Hoston), use Find & Replace (Ctrl+H): find the wrong spelling, replace it with the right one, and tick “Match entire cell contents” so Houston inside a longer name isn’t touched. Filter the column first to see every variant at once: the filter list shows each distinct spelling.

    Common mistakes

    • <> or = to detect changes. Both ignore case. Use EXACT.
    • PROPER on the state. PROPER("tx") gives Tx. Codes need UPPER.
    • TRIM alone. It fixes 'Houston ' but leaves houston and HOUSTON as they are.
    • Non-breaking spaces. Text pasted from a web page can carry character 160, which TRIM leaves alone. in Excel, SUBSTITUTE(D2,CHAR(160)," ") turns it into a normal space first. Our export doesn’t have any, but you will meet them.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.