RegEX function or VBA Macro for multiple country Postcode check

JAGIUS

New Member
Joined
Apr 6, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
HI all,

New here so please go easy :)

I am wanting to create a function or query (whichever works better) which will do the following:

1. Run through a column of postcodes entered manually by the inputter and highlight entries which do not match the specified RegEx expression.
2. The regEx expression list used will be determined by which ISO country code the postcode is assigned to.

I am able to find loads of code on line for a postcode checker for one country but not seen anything for multiple countries - I assume a vlookup table may have to be combined wit the RegEx checker but cannot fathom how to implement this.

So in summary a "simple" regEx checker based on a list of postcodes BUT the regEx expressions will VARY based on which country the postcode is assigned to

Hope the above makes sense

TIA
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You can download a list of all postal codes - all countries - from the following website:

All Postal Code - All countries (Geonames)

Once you've downloaded the list, you can create a simple list of postal codes & their associated ISO country codes. Personally, I would use it like the following brief demo (with lookup functions & conditional formatting to highlight when not found).

Book1
ABCDEFG
1ISO CodePostal CodeList to CheckISO Code(s)
2FR4661246612FR
3ES4661346613ESUKUSA
4UK46613511444Unlisted
5USA4661346614FR
6FR4661446615FR
7FR46615
8
Sheet3
Cell Formulas
RangeFormula
E2,E4:E6,E3:G3E2=TRANSPOSE(FILTER($A$2:$A$7,$B$2:$B$7=D2,"Unlisted"))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D2:D7Expression=COUNTIF($B$2:$B$7,D2)=0textNO
 
Upvote 0
You can download a list of all postal codes - all countries - from the following website:

All Postal Code - All countries (Geonames)

Once you've downloaded the list, you can create a simple list of postal codes & their associated ISO country codes. Personally, I would use it like the following brief demo (with lookup functions & conditional formatting to highlight when not found).

Hi Thanks for this and yes it works fine but it requires the list of postcodes to be populated well and upto date which for certain countries the coverage is not great. What I was really after is for a RegEx check so that would cover everything.
 
Upvote 0
Regex will give you the right pattern for a country's post codes, but it won't be able to check whether they're valid & up to date. If you have a look at the download, some countries don't have a single pattern anyway.
Anyhow, my post was merely a suggestion 🙂
 
Upvote 0
Regex will give you the right pattern for a country's post codes, but it won't be able to check whether they're valid & up to date. If you have a look at the download, some countries don't have a single pattern anyway.
Anyhow, my post was merely a suggestion 🙂
Yes and greatful that could come in useful but I am ideally after a pattern matching exercise for now but again thanks for the input
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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