Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default international postal codes

Every month I need to validate internation postal codes for acceptable
formats in an Excel 2003 spreadsheet. Some countries have numerous
acceptable formats (up to about 20 or so for some) using letters and numbers
and sometimes the initials of the country. For example:

l = letter
n = number

Finland
nnnnn
FI nnnnn
FI-nnnnn
FInnnnn
FIN nnnnn
FIN-nnnnn
FINnnnnn

Canada
lnl nln
lnl-nln
lnlnln

Is there a function in Excel 2003 that can do this kind of validation?
--
JJ Johnson
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,393
Default international postal codes

Actually the Canada Post like to see LNL NLN with the space
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
www.stfx.ca/people/bliengme
remove caps from email

"JJ Johnson" wrote in message
...
Every month I need to validate internation postal codes for acceptable
formats in an Excel 2003 spreadsheet. Some countries have numerous
acceptable formats (up to about 20 or so for some) using letters and
numbers
and sometimes the initials of the country. For example:

l = letter
n = number

Finland
nnnnn
FI nnnnn
FI-nnnnn
FInnnnn
FIN nnnnn
FIN-nnnnn
FINnnnnn

Canada
lnl nln
lnl-nln
lnlnln

Is there a function in Excel 2003 that can do this kind of validation?
--
JJ Johnson



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default international postal codes

Hi JJ,

Firstly you would need to collate the various international postal code
exmaples.

Once you have these you can continue to write VBA code and use IF to verify
the country and postal code format. Add a comment in another column.

For example;
Lets say for this example you have "Canada" entered in cell "A1" and the
exmaple postal code of "A1A 2B2" in cell "B1" in your spreadsheet.

Open the Visual Basic for Applications Editor (Alt-F11) and enter/copy the
following code;

Sub checkPostalCodes()

'Declare Variables
Dim CountryRegion As String
Dim PostalCode As String

'Assign Spreadsheet reference
CountryRegion = Range("A1")
PostalCode = Range("B1")

'Use if function to check postal code is correct
If CountryRegion = "Canada" And PostalCode Like "[A-Z][0-9][A-Z]
[0-9][A-Z][0-9]" Then
'if true
Range("C1") = "OK"
Else
'if false
Range("C1") = "Error"
End If

'Finish
End Sub

All you would have to do know is use a loop to process through all your
records/rows of data. I hope this helps, and if you want more information
on Postal Codes and Macros then visit the MSDN web address below;

http://msdn2.microsoft.com/en-us/library/bb177324.aspx

Cheers

Ross


"JJ Johnson" wrote in message
...
Every month I need to validate internation postal codes for acceptable
formats in an Excel 2003 spreadsheet. Some countries have numerous
acceptable formats (up to about 20 or so for some) using letters and
numbers
and sometimes the initials of the country. For example:

l = letter
n = number

Finland
nnnnn
FI nnnnn
FI-nnnnn
FInnnnn
FIN nnnnn
FIN-nnnnn
FINnnnnn

Canada
lnl nln
lnl-nln
lnlnln

Is there a function in Excel 2003 that can do this kind of validation?
--
JJ Johnson


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default international postal codes

Hi JJ,

Sorry I forgot to add the "variations" to that code. See below, it will
also test the different variations for Canada;
lnl nln
lnl-nln
lnlnln

Sub checkPostalCodes()

'Declare Variables
Dim CountryRegion As String
Dim PostalCode As String

'Assign Spreadsheet reference
CountryRegion = Range("A1")
PostalCode = Range("B1")

'Use if function to check postal code is correct
If CountryRegion = "Canada" And PostalCode Like "[A-Z][0-9][A-Z]
[0-9][A-Z][0-9]" Then
'various if true
Range("C1") = "OK"
ElseIf CountryRegion = "Canada" And PostalCode Like
"[A-Z][0-9][A-Z]-[0-9][A-Z][0-9]" Then
Range("C1") = "OK"
ElseIf CountryRegion = "Canada" And PostalCode Like
"[A-Z][0-9][A-Z][0-9][A-Z][0-9]" Then
Range("C1") = "OK"
Else
'if false
Range("C1") = "Error"
End If

'Finish
End Sub

Hope this helps

Cheers

Ross



"JJ Johnson" wrote in message
...
Every month I need to validate internation postal codes for acceptable
formats in an Excel 2003 spreadsheet. Some countries have numerous
acceptable formats (up to about 20 or so for some) using letters and
numbers
and sometimes the initials of the country. For example:

l = letter
n = number

Finland
nnnnn
FI nnnnn
FI-nnnnn
FInnnnn
FIN nnnnn
FIN-nnnnn
FINnnnnn

Canada
lnl nln
lnl-nln
lnlnln

Is there a function in Excel 2003 that can do this kind of validation?
--
JJ Johnson


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell format for Canadian postal codes mmcstech Excel Discussion (Misc queries) 10 April 21st 23 09:01 PM
formula for Canadian postal codes LB Excel Worksheet Functions 7 July 18th 07 12:07 AM
formula for Canadian Postal Codes LB Excel Worksheet Functions 6 January 25th 07 06:30 PM
UK Postal codes in Excel Paul G Excel Worksheet Functions 6 October 30th 06 12:07 PM
Distances between Postal Codes Irfan Excel Discussion (Misc queries) 1 May 31st 06 10:49 PM


All times are GMT +1. The time now is 02:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"