Remove all Non UK or incorrectly formatted postcodes from column

Lorr81

New Member
Joined
Mar 21, 2016
Messages
38
Hi,

I have a sheet that has postcodes from all over the globe not to mention some really bad data entry, what I need to do is remove these leaving only the correctly formatted UK post codes.

I have tried and looked every where for a macro, formula or conditional formatting trick but with not joy, is this even possible and if so any advice would be greatly appreciated.

Thank you,

Lorraine
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
FYI The function created by xld in the link, that kgkev supplied does not work.
Also, you need to be aware that other countries also use similar Postcodes to the UK.
 
Upvote 0
really? it worked fine for me

[TABLE="width: 167"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]AB25 4LP[/TD]
[TD="align: center"]TRUE[/TD]
[/TR]
[TR]
[TD]S1 7JW[/TD]
[TD="align: center"]TRUE[/TD]
[/TR]
[TR]
[TD]EC2N 4AG[/TD]
[TD="align: center"]TRUE[/TD]
[/TR]
[TR]
[TD]E1B 4WE[/TD]
[TD="align: center"]TRUE[/TD]
[/TR]
[TR]
[TD]WR8 7QP[/TD]
[TD="align: center"]TRUE[/TD]
[/TR]
[TR]
[TD]Wr8 7Qp[/TD]
[TD="align: center"]TRUE[/TD]
[/TR]
[TR]
[TD]WW4 AAA[/TD]
[TD="align: center"]FALSE[/TD]
[/TR]
[TR]
[TD]WW AAA[/TD]
[TD="align: center"]FALSE[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
I got errors on these (amongst others)


Excel 2013 32 bit
A
2015EN9 1AL
2016EN9 2RZ
2017EN9 2SQ
2018EN9 3JR
2019EN9 3PU
2020EN9 3TY
2021EN9 3YZ
2022EN9 3ZT
2023EX10 9XZ
2024EX10 9YF
2025EX10 9YN
2026EX11 1SG
2027EX11 1ZU
2028EX12 3RB
2029EX13 5UW
Pcode
 
Upvote 0
You're right. It seems the section to account for EC1A doesn't allow for EX11 or EN9


Code:
Function VPC(ByVal PostCode As String) As Boolean
Dim Sections() As String
    PostCode = UCase$(PostCode)
    Sections = Split(PostCode)
    If  (Sections(1) Like "#[A-Z][A-Z]" And _
        (Sections(0) Like "[A-Z]#" Or Sections(0) Like "[A-Z]#[0-9ABCDEFGHJKSTUW]" Or _
         Sections(0) Like "[A-Z][A-Z]#" Or Sections(0) Like "[A-Z][A-Z]#[0-9ABEHMNPRVWXY]")) Then
        VPC = ((Sections(0) Like "[BEGLMSW]#*" Or _
                          Sections(0) Like "A[BL]#*" Or _
                          Sections(0) Like "B[ABDHLNRST]#*" Or _
                          Sections(0) Like "C[ABFHMORTVW]#*" Or _
                          Sections(0) Like "D[ADEGHLNTY]#*" Or _
                          Sections(0) Like "E[HNX]#*" Or _
                          Sections(0) Like "E[C]#[AMNRVY]" Or _
                          Sections(0) Like "F[KY]#*" Or _
                          Sections(0) Like "G[LU]#*" Or _
                          Sections(0) Like "H[ADGPRSUX]#*" Or _
                          Sections(0) Like "I[GPV]#*" Or _
                          Sections(0) Like "K[ATWY]#*" Or _
                          Sections(0) Like "L[ADELNSU]#*" Or _
                          Sections(0) Like "M[EKL]#*" Or _
                          Sections(0) Like "N[EGNPRW]#*" Or _
                          Sections(0) Like "O[LX]#*" Or _
                          Sections(0) Like "P[AEHLOR]#*" Or _
                          Sections(0) Like "R[GHM]#*" Or _
                          Sections(0) Like "S[AEGKLMNOPRSTWY]#*" Or _
                          Sections(0) Like "T[ADFNQRSW]#*" Or _
                          Sections(0) Like "W[ACDFNRSV]#*" Or _
                          Sections(0) Like "UB#*" Or _
                          Sections(0) Like "YO#*" Or _
                          Sections(0) Like "ZE#*") And _
                          Sections(1) Like "*#[!CIKMOV][!CIKMOV]")
    Else
        VPC = False
    End If
End Function


That should fix it.
 
Last edited:
Upvote 0
Hi All,

Thank you for the suggestions however it is still not working, I am getting no results at all, have I done something wrong?

Lorr
 
Upvote 0
Have you added this function into a new module on the workbook?
 
Upvote 0
Lorr

What exactly have you tried?

The functions that have been suggested would be used like standard Excel worksheet functions to tell you if a postcode was valid or not.

For example to test if the postcode in A1 was valid you would use this.

=VPC(A1)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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