Formula to Remove characters from a cell

RLJ

Active Member
Joined
Mar 15, 2011
Messages
417
Office Version
  1. 365
Platform
  1. Windows
I would like a formula to remove a possible zip code from a cell. I get data from a Client Database and want to remove the zip code from the cell as it is duplicated in another cell. All I want is the City/State.

Here is my problem... It is a client database so I do not have control over how the information is input. The field could inculde the zip+0000, just the zip, a blank field or it could be another part of the address. As indicated below.

Excel 2010
I
265NEW YORK, NY 10020
266LOS ANGELES, CA 90067-3100
267NEW YORK, NY 10022-2000
268NEW YORK, NY 10022
269NEW YORK, NY 10022
270NEW YORK, NY 10166
271NEW YORK, NY 10166
272
27325 MAIN STREET HACKENSACK

<COLGROUP><COL><COL></COLGROUP><THEAD>
</THEAD><TBODY>
</TBODY>
Additional Contacts

As I see it the formula needs to look for a cell with a comma in it and then after 4 characters to the right remove it, and if no comma exisits, then copy original cell as is.

Thanks for your help!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi,

Assuming you're using Excel 2007 or later

=IFERROR(LEFT(G5,LEN(G5)+3-FIND(",",G5)),G5)

Just change G5 for you cell reference

Hope this helps

Chris
 
Last edited:
Upvote 0
Spoke a little too soon. The formula works, but can it be changed to read after the last comma in the cell. I just came across one that is New York,, NY 10022-3598. So with Jonmo1's equation I ended up with New York,, N

Thanks for your help!
 
Upvote 0
This works for the sample provided.
Press Alt+F11, copy the code into an empty module, check Microsoft VBScript Regular Expressions 5.5 option_
at Tools/References then use this as a User Defined Function.
Code:
Function DeleteZip(c As String) As String
    With CreateObject("VBScript.RegExp")
        .Pattern = "[-\d\s]+$"
        If .Test(c) Then DeleteZip = .Replace(c, "")
    End With
End Function
 
Upvote 0
Maybe this formula:

Code:
=REPLACE(B1,FIND(C1&"X",B1&"X"),20,"")

Where C is the column of the zip code.

Markmzz
 
Upvote 0
This formula should work for you...

=IF(ISNUMBER(-RIGHT(I265)),LEFT(I265,LEN(I265)-LEN(TRIM(RIGHT(SUBSTITUTE(I265," ",REPT(" ",99)),99)))-1),IF(LEN(I265),I265,""))
 
Last edited:
Upvote 0
test this formula also
=LEFT(I266,LEN(I266)-LEN(MID(I266,MIN(FIND({0,1,2,3,4,5,6,7,8,9},I266&"0123456789")),255)))
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,837
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top