Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

VBA Excel Function for Postcodes

  • Please log in to reply




  • 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


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