Delete Repetitive occurrence in a cell

Blessy Clara

Board Regular
Joined
Mar 28, 2010
Messages
201
Hi,

i have an excel sheet with an Address column - The Zip code is repeated twice in the column and i wanna remove the repetition -

[TABLE="width: 500"]
<tbody>[TR]
[TD]Zurich House, Level 5, 201 Leichhardt St Spring Hill QLD 4004 , 4004[/TD]
[TD]Zurich House, Level 5, 201 Leichhardt St Spring Hill QLD 4004[/TD]
[/TR]
[TR]
[TD]Zurich House, 6/ 75 Denham St Townsville QLD 4810 , 4810[/TD]
[TD]Zurich House, 6/ 75 Denham St Townsville QLD 4810[/TD]
[/TR]
[TR]
[TD]Zunker St Burnett Heads QLD 4670 , 4670[/TD]
[TD]Zunker St Burnett Heads QLD 4670[/TD]
[/TR]
[TR]
[TD]Zaknic Pl Bunbury WA 6230[/TD]
[TD]Zaknic Pl Bunbury WA 6230[/TD]
[/TR]
[TR]
[TD]1st Floor, 7 Bayfield St Rosny TAS, 7018 Australia , 7018[/TD]
[TD]1st Floor, 7 Bayfield St Rosny TAS, 7018 Australia[/TD]
[/TR]
[TR]
[TD]address[/TD]
[TD]Result[/TD]
[/TR]
</tbody>[/TABLE]



Thank you in advance for your time and effort
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Something like =TRIM(left(A1,len(a1)-6)) ?
If the sample data is accurate, then this would fail for the second last example in post 1.



@Blessy Clara
You could try this user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Note from the last 2 examples in my data, that I have tried to ensure that any repeated 4-digit code is in fact a postcode, not a street number, before it is deleted. See how it goes.

Code:
Function DedupePostcode(s As String) As String
  Static RX As Object

  If RX Is Nothing Then Set RX = CreateObject("VBScript.RegExp")
  RX.Pattern = "([A-Z]{2,3}.*?)(\d{4})(.*?)( *,* *\2$)"
  DedupePostcode = RX.Replace(s, "$1$2$3")
End Function

Excel Workbook
AB
1Zurich House, Level 5, 201 Leichhardt St Spring Hill QLD 4004 , 4004Zurich House, Level 5, 201 Leichhardt St Spring Hill QLD 4004
2Zurich House, 6/ 75 Denham St Townsville QLD 4810 , 4810Zurich House, 6/ 75 Denham St Townsville QLD 4810
3Zunker St Burnett Heads QLD 4670 , 4670Zunker St Burnett Heads QLD 4670
4Zaknic Pl Bunbury WA 6230Zaknic Pl Bunbury WA 6230
51st Floor, 7 Bayfield St Rosny TAS, 7018 Australia , 70181st Floor, 7 Bayfield St Rosny TAS, 7018 Australia
62000 George St Sydney NSW 20002000 George St Sydney NSW 2000
71st Floor, 2000 George St Sydney NSW 2000, 20001st Floor, 2000 George St Sydney NSW 2000
Sheet1
 
Last edited:
  • Like
Reactions: Biz
Upvote 0
Thank you to everyone for taking time to stop by and respond -
arthurbr - Thanks, but there was a problem, as the last stated Example which didnt hve Postal digit of 4 numbers - it removed the terms QLD Aus = Q kinda like that (jst an ex)
Peter_SSs
Thank you very much for the wonderful UDF - and for stunning perception of my requirement (considering records without zipcode) - this is exactly what i required
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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