Removing excess spaces & characters (postcodes)

Marcus

New Member
Joined
Mar 21, 2002
Messages
37
Hi chaps, another easy one I'm sure. I have a column of approx 3000 postcodes to import into a database, however they all have either excess spaces, commas or other punctuation after the postcode which will not allow them to import correctly. How do I "cleanse" them into the format AB12 3CD?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
On 2002-04-02 00:10, Marcus wrote:
Hi chaps, another easy one I'm sure. I have a column of approx 3000 postcodes to import into a database, however they all have either excess spaces, commas or other punctuation after the postcode which will not allow them to import correctly. How do I "cleanse" them into the format AB12 3CD?

Care to give some typical examples that have extraneous punctuation like comma, period, etc.?
 
Upvote 0
On 2002-04-02 00:29, Marcus wrote:
eg.

CX1 1BY. .,,!
ECRM 7DH. : .-

ASAP-Utilities is good to have, as Ian suggested. However, it fails to remove "!" from your sample.

In B1 enter:

=SUBSTITUTE(TRIM(A1)," ","@",1)

In C1 enter:

=SUBSTITUTE(SUBSTITUTE(B1,RIGHT(B1,SUMPRODUCT((LEN(B1)-LEN(SUBSTITUTE(B1,{".",",",":","-","!"," "},""))))),""),"@"," ")

Select B1:C1, double click on the fill handle in the lower right corner (the little black square) in order to copy down these formulas.

Copy everything in C and execute Edit|Paste Special >Values. Hereafter you can delete columns A and B.

If there are more puntuation marks I didn't cover, include them in the

{".",",",":","-","!"," "}

part of the second formula.

Aladin
 
Upvote 0
Hi Marcus

It's extremely easy to create your own macro to do this. Try this one on a selected Column of data.


Code:
Sub GoAway()
Dim i As Integer, strCha As String

 On Error Resume Next
    For i = 1 To 27
      strCha = Choose(i, "~", "`", "!", "@", "#", "$", "%", "^", _
        "&", "~*", "(", ")", "_", "[", "]", "{", "}", "|", "", ":", _
        ";", ",", "<", ".", ">", "?", "/")
    
        Selection.Replace What:=strCha, Replacement:="", LookAt:=xlPart, _
                  SearchOrder:=xlByRows, MatchCase:=False
   Next i
 On Error GoTo 0
 
End Sub
 
Upvote 0
Cheers all for problem solving, and for giving me a few more ideas. Many thanks indeed.
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,170
Members
448,870
Latest member
max_pedreira

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