excel -

%3CLINGO-SUB%20id%3D%22lingo-sub-1109994%22%20slang%3D%22en-US%22%3Eexcel%20-%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1109994%22%20slang%3D%22en-US%22%3E%3CP%3Ehow%20to%20parse%20data%20in%20a%20field%20i.e.%20field%20contains%3A%26nbsp%3B%20address%2C%20city%20and%20zip%20code%20-%20i%20want%20to%20isolate%20ZIP%20code%20in%20a%20new%20cell%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1109994%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1110017%22%20slang%3D%22en-US%22%3ERe%3A%20excel%20-%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1110017%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F519454%22%20target%3D%22_blank%22%3E%40Mike3812%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20have%20Excel%202013%20or%20later%2C%20you%20may%20flash%20fill%20the%20Zip%20Codes.%20See%20how%20to%20use%20flash%20fill%20here%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.office.com%2Fen-us%2Farticle%2Fusing-flash-fill-in-excel-3f9bcf1e-db93-4890-94a0-1578341f73f7%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.office.com%2Fen-us%2Farticle%2Fusing-flash-fill-in-excel-3f9bcf1e-db93-4890-94a0-1578341f73f7%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20the%20Zip%20Codes%20are%20always%20the%20last%205%20characters%20in%20each%20field%2C%20then%20that%20could%20be%20the%20following%20formula%3A%3C%2FP%3E%3CP%3E%3DRIGHT(Text%2C%205)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1110149%22%20slang%3D%22en-US%22%3ERe%3A%20excel%20-%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1110149%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F519454%22%20target%3D%22_blank%22%3E%40Mike3812%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20want%20to%20parse%20even%20more%20(in%20this%20case%2C%20isolating%20the%20city%20name)%20you%20should%20familiarize%20yourself%20with%20the%20set%20of%20text%20functions%2C%20including%20at%20the%20very%20least%20the%20following%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3ELEFT%3C%2FSTRONG%3E%2C%20which%20can%20isolate%20a%20designated%20number%20of%20characters%20from%20the%20left%3C%2FP%3E%3CP%3E%3CSTRONG%3ERIGHT%3C%2FSTRONG%3E%2C%20same%20as%20above%20from%20the%20right%3C%2FP%3E%3CP%3E%3CSTRONG%3EMID%3C%2FSTRONG%3E%2C%20isolates%20characters%20from%20within%20the%20middle%3B%20you%20designate%20start%20and%20end%20point%3C%2FP%3E%3CP%3E%3CSTRONG%3ELEN%3C%2FSTRONG%3E%20will%20calculate%20the%20length%20of%20a%20text%20field%3C%2FP%3E%3CP%3E%3CSTRONG%3EFIND%3C%2FSTRONG%3E%20will%20find%20a%20given%20character%20in%20a%20text%20field%2C%20beginning%20at%20point%20x%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20if%20there's%20general%20consistency%20in%20your%20field%2C%20it%20would%20be%20possible%20even%20to%20isolate%20the%20city%20name.%20If%20(this%20is%20where%20consistency%20matters)%20commas%20are%20used%20to%20separate%20street%20from%20city%20and%20city%20from%20zip%2C%20and%20zip%20is%20always%205%20characters%20long%2C%20something%20like%20the%20following%20could%20work%20to%20parse%20out%20city%20name%20from%20your%20text%20(assuming%20it's%20in%20cell%20C5)%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DMID(C5%2CFIND(%22%2C%22%2CC5)%2B2%2C(FIND(%22%2C%22%2CC5%2CFIND(%22%2C%22%2CC5)%2B1)-FIND(%22%2C%22%2CC5))-2)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EI%20just%20tested%20this%20formula%20successfully%20on%20a%20street%20address%20in%20NYC%2C%20where%20the%20city%20name%20consists%20of%20two%20words.....%26nbsp%3B%20The%20formula%20below%20also%20works%2C%20coming%20at%20it%20from%20a%20different%20direction%20(and%20assuming%20zip%20is%20always%20the%20last%205%20characters)%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DRIGHT(LEFT(C5%2CLEN(C5)-7)%2CLEN(C5)-FIND(%22%2C%22%2CC5)-8)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20are%20two%20basic%20points%20that%20need%20to%20be%20made%20here%3A%3C%2FP%3E%3CUL%3E%3CLI%3EThe%20text%20functions%20are%20very%20useful%20in%20parsing%20out%20fields%20like%20the%20one%20you%20are%20facing%2C%20where%20multiple%20data%20elements%20have%20been%20combined%20into%20one%20field%3C%2FLI%3E%3CLI%3E%3CEM%3EMore%20important%3A%20it's%20better%20database%20design%20%3CSTRONG%3E%3CU%3Ealways%3C%2FU%3E%3C%2FSTRONG%3E%20to%20keep%20distinct%20data%20elements%20in%20their%20own%20distinct%20fields%20because%20there's%20another%20text%20function--%3CSTRONG%3ECONCATENATE%3C%2FSTRONG%3E--that%20easily%20assembles%20distinct%20fields%2C%20far%20easier%20than%20the%20parsing.%3C%2FEM%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor

how to parse data in a field i.e. field contains:  address, city and zip code - i want to isolate ZIP code in a new cell

2 Replies
Highlighted

Hello @Mike3812,

 

If you have Excel 2013 or later, you may flash fill the Zip Codes. See how to use flash fill here:

https://support.office.com/en-us/article/using-flash-fill-in-excel-3f9bcf1e-db93-4890-94a0-1578341f7...

 

If the Zip Codes are always the last 5 characters in each field, then that could be the following formula:

=RIGHT(Text, 5)

Highlighted

@Mike3812 

 

If you want to parse even more (in this case, isolating the city name) you should familiarize yourself with the set of text functions, including at the very least the following:

LEFT, which can isolate a designated number of characters from the left

RIGHT, same as above from the right

MID, isolates characters from within the middle; you designate start and end point

LEN will calculate the length of a text field

FIND will find a given character in a text field, beginning at point x

 

So if there's general consistency in your field, it would be possible even to isolate the city name. If (this is where consistency matters) commas are used to separate street from city and city from zip, and zip is always 5 characters long, something like the following could work to parse out city name from your text (assuming it's in cell C5):

=MID(C5,FIND(",",C5)+2,(FIND(",",C5,FIND(",",C5)+1)-FIND(",",C5))-2)

I just tested this formula successfully on a street address in NYC, where the city name consists of two words.....  The formula below also works, coming at it from a different direction (and assuming zip is always the last 5 characters):

=RIGHT(LEFT(C5,LEN(C5)-7),LEN(C5)-FIND(",",C5)-8)

 

There are two basic points that need to be made here:

  • The text functions are very useful in parsing out fields like the one you are facing, where multiple data elements have been combined into one field
  • More important: it's better database design always to keep distinct data elements in their own distinct fields because there's another text function--CONCATENATE--that easily assembles distinct fields, far easier than the parsing.