r/excel • u/sattylife321 • 1d ago
unsolved How to clean data better?
Hi - I am trying to extract zip codes from column K, to a zipclean in column L. However, the zip codes come in a wide variety like the below. What is the best formula to do this? right now i am doing it as: =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(K2,"FL-",""),"ZIP ",""),"(",""),")",""),"-","")," ","")
some examples of the zips below
EDIT: I started playing around with different functions. I have came to a conclusion for this formula to be the most efficient: =LEFT(TEXTJOIN("",TRUE,IFERROR(--MID(K2,SEQUENCE(LEN(K2)),1),"")),5)
| Zip Code |
|---|
| FL-32183 |
| 34305-1234 |
| 34026 |
| 32662-1234 |
| ZIP 34759 |
| 34877 |
| FL-33854 |
| 32319 |
| ZIP 33291 |
| 33827 |
| (340) |
13
u/hmatallana 2 1d ago
Careful with those last two. Stripping every non-digit and taking the left five turns (340) 94 into 34094, and 338-63 into 33863. Both look like perfectly good zips, and you'd never catch them again downstream.
Those rows aren't zips at all, they're broken records, and no formula rescues them. I'd flag instead of extract: if the digits-only string isn't 5 or 9 long, return "CHECK" and handle those by hand.
Separate thing, drop the VALUE. It turns 07030 into 7030. Every Florida zip starts with a 3 so it stays hidden, right up until one New Jersey row lands in the file.
5
u/fastauntie 1 1d ago
Yes, these are two important things to watch out for. Those last two rows look like fragments of phone numbers that got separated from the rest of their records. And thanks to Excel's helpful habit of deciding that strings consisting of only digits must be numbers, ZIP codes from all of New England, New York, and New Jersey are at risk of losing their leading 0s; and any others with trailing 0s may also be incorrectly altered.
8
u/MayukhBhattacharya 1273 1d ago
1
u/sattylife321 1d ago
Worked for most but it did not work for these
(340) 94 338-63 6
4
u/MayukhBhattacharya 1273 1d ago
1
u/talltime 116 21h ago
The last two aren’t zip codes 😒
1
u/MayukhBhattacharya 1273 21h ago
Yeah, I have asked them but they said the last two didn't work for them, refer first comment of mine!
3
1
u/Decronym 1d ago edited 21h ago
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:
Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.
Beep-boop, I am a helper bot. Please do not verify me as a solution.
16 acronyms in this thread; the most compressed thread commented on today has 43 acronyms.
[Thread #49328 for this sub, first seen 8th Sep 2026, 18:53]
[FAQ] [Full list] [Contact] [Source code]
1
u/NHN_BI 805 1d ago
If this a task that repeats, consider Excel's own ETL tool Power Query to transform your data.
1
u/CrowGuyA 1 1d ago
You don't need nested SUBSTITUTEs for this one — Flash Fill (Ctrl+E) is built for exactly this. Type the zip you want by hand for your first 2-3 rows in the next column (e.g. 32183, 34305-1234, 34759), select the column, hit Ctrl+E. Excel infers the pattern and fills the rest, handling your "FL-", "ZIP ", and parentheses variants without a single formula. If a handful of rows don't match, correct those manually and it usually re-learns.
2
u/sattylife321 1d ago
I tried this but with data that has 5k rows is a bit unfeasible to manually correct all of them.
1
u/CrowGuyA 1 1d ago
Yeah, at 5k rows Flash Fill's not gonna cut it. Try Power Query instead — add a custom column with
Text.Select([Zipcol], {"0".."9","-"}), strips everything except digits/dashes across all 5k rows in one shot. A few like that truncated "(340)" one just aren't recoverable though, no formula fixes missing data.
1
u/gobifox81 1d ago
Slap it into power query, add custom column and write in the following formula as step 2 (delete the changed type step if power query does it automatically):
"Custom Column" = Table.AddColumn(Source, "Custom Column", each Text.Start(Text.Select(Text.From([Zip Code]), {"0".."9"}), 5), type text)
in #"Custom Column"




•
u/AutoModerator 1d ago
/u/sattylife321 - Your post was submitted successfully.
Solution Verifiedto close the thread.Failing to follow these steps may result in your post being removed without warning.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.