Analyze your problem!
- you want to split your address string at the comma
- you then want to split the right fragment from (1) at the first blank
ad 1): you get the position of the comma using =FIND(",", A1)
, and use the result in a =LEFT(...)
and a =RIGHT(...)
- for the latter you also need the string length (=LEN(...)
)
- B1:
=LEFT(A1;FIND(",";A1)-1)
- C1:
=RIGHT(A1;LEN(A1)-LEN(B1)-2)
Now comes the fun part ... in your 3rd example we mustn't split on the first comma, but on the third comma ... or as a more general rule, we always must split on the last comma .... but how do we find how many commas we have in the string, to feed its position as an additional argument into the =FIND(...)
function?
Quick answer: look at Stackoverflow (exactly here) ... very clever ... subtract the length of the string with all commas removed from the original length, and then replace the last occurence of the comma by something else, because =SUBSTITUTE(...)
works on occurence, whilst =FIND()
only works on position. If you incorporate all this this, you will have
- B1:
=LEFT(A1;FIND("@";SUBSTITUTE(A1;",";"@"; LEN(A1)-LEN(SUBSTITUTE(A1;",";""))))-1)
--> full address
- C1: (same as above)
Here we use "@" as a neutral substitution string for the final comma as we asume that no address uses the "@"
ad 2): you apply the above (with blank instead of comma) once again to the right part. You can use the simple first version of the formulae as it's clear you want to split at the first blank
- D1:
=LEFT(C1;FIND(" ";C1)-1)
--> state
- E1:
=RIGHT(C1;LEN(C1)-LEN(D1)-1)
--> ZIP code