Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VBA Excel Function for Postcodes


  • Please log in to reply

#1
csit17

csit17

    Member

  • Member
  • PipPip
  • 27 posts
Hello All,

I am trying to write a UDF to extract the first 3 or 4 characters and first character of a UK postcode (If supplied).

Examples of the various postcodes I recieve - L1 1HY, L12 1HY, LN12 1HY, L11HY, L121HY, LN121HY, L1, L12, LN12 ETC

I have started writing the below but am struggling to work out the best way to do it.

Function Halfpostcode(Postcode As String, District As Integer) As String
Postcode = Trim(Postcode)


Select Case IsNumeric(Application.WorksheetFunction.Search(" ", (Postcode)))
    Case True
    spaceloc = Application.WorksheetFunction.Search(" ", (Postcode))
    If Len(Postcode) - spaceloc <= 3 Then Halfpostcode = Left(Postcode, Application.WorksheetFunction.Search(" ", (Postcode)))

Many Thanks in advance
Mark (CSIT17)
  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP