View Single Post
  #10  
Old 02-08-2007, 01:06 AM
gajendra.gupta gajendra.gupta is offline
Registered User
 
Join Date: 19 Jan 2007
Location: Bangalore, India
Posts: 66
gajendra.gupta is becoming part of the community
I beleive this might also helpful if you are entering Postcode in Range 'A1'.

Sub Postal_Verify()
If Len(Range("A1").Text) = 6 And _
IsAlpha(Mid(Range("A1").Text, 1, 1)) = True And _
IsAlpha(Mid(Range("A1").Text, 3, 1)) = True And _
IsAlpha(Mid(Range("A1").Text, 5, 1)) = True And _
IsNumeric(Mid(Range("A1").Text, 2, 1)) = True And _
IsNumeric(Mid(Range("A1").Text, 4, 1)) = True And _
IsNumeric(Mid(Range("A1").Text, 6, 1)) = True Then
Range("A1") = Left(Range("A1"), 3) & " " & Right(Range("A1"), 3)
Else
MsgBox "Invalid Postal Code."
End If
End Sub
Function IsAlpha(chr As String) As Boolean
If Asc(chr) >= 97 And Asc(chr) <= 122 Or Asc(chr) >= 65 And Asc(chr) <= 90 Then
IsAlpha = True
Else
IsAlpha = False
End If
End Function

Regards,
Gajendra Gupta
Reply With Quote