Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Cell format for Canadian postal codes | Excel Discussion (Misc queries) | |||
formula for Canadian postal codes | Excel Worksheet Functions | |||
formula for Canadian Postal Codes | Excel Worksheet Functions | |||
UK Postal codes in Excel | Excel Worksheet Functions | |||
Distances between Postal Codes | Excel Discussion (Misc queries) |