How can I auto expand a list of UK postcode ranges for clean lookup

JeremyLittman

New Member
Joined
Jan 2, 2013
Messages
3
Hi there - I hope someone can help.

I have a very limited knowledge of VB with an intermediate knowledge of formulas and am using Excel 2011 for Mac.

I wish to create a spreadsheet that will enable me to lookup which electricity distribution network companies operate in specific regions in the UK based on a postcode search and am looking for some code that will save me hours of error prone work. I believe there are 2 main steps to this; an automated data clean up and a robust, partial postcode lookup function.

The lookup dataset I am using comprises of 14 columns for each Distribution Network containing partial postcode range e.g.

SP Energy Networks
CH 1-8
CW 1-11
L 1-39
L 41-49
L 60-70, 72
LL 11-49
LL 51-78
LL 7
PR 8, 9

PART 1

You will see there are combinations of 3 data types contained in the above example cells; ranges, lists and single codes. Rather than manually expanding the ranges and lists, I wish to automate the process so I end up with a complete expanded list of codes in each column e.g.

SP Energy Networks
CH 1
CH 2
CH 3
...
CW 1
CW 2
...
L 61
L 62
...
L 72
...
LL 7
PR 8
PR 9

PART 2

The expanded dataset in part 1 will only contain partial postcodes comprising of the area and district (see postcode format information below).

I will be looking up multiple lists of postcodes so wish to be able to achieve the following example query in a separate sheet:

Column AColumn B
(input)(result)
CH1 4LQSP Energy Networks
WC1A 3AUUK Power Network
YO5 4NPNorthern Powergrid
PA60 7AYSSE Power

<tbody>
</tbody>


There will be occasion when a postcode input contains more than 1 lookup result across different regions i.e. CW12 4NR will find both CW1 and CW12 in the source data. The lookup logic must therefore search each integer from 0 through to 99.

POSTCODE FORMAT

In order to understand the logic required for the lookup, a postcode is made up of the following elements:

PO1A 3AX

PO - the area. There are 124 postcode areas in the UK denoted by one or two alpha characters

1A - the district. There are approximately 20 Postcode districts in an area denoted by numbers ranging from 0 to 99. In London a further alpha character is used to divide some districts into sub divisions e.g. EC1A

3 - the sector. There are approximately 3000 addresses in a sector

AX - the unit. There are approximately 15 addresses per unit.


The following list shows all valid Postcode formats. "A" indicates an alphabetic character and "N" indicates a numeric character.

FORMATEXAMPLE
AN NAAM1 1AA
ANN NAAM60 1NW
AAN NAACR2 6XH
AANN NAADN55 1PT
ANA NAAW1A 1HQ
AANA NAAEC1A 1BB

<tbody>
</tbody>

The above postcode format information has been summarised from the following web source:

http://www.mrs.org.uk/pdf/postcodeformat.pdf

The Excel data file containing the postcode data can be downloaded from here:

https://dl.dropbox.com/u/47971826/Example excel/DNO Calculator.xlsx

Many thanks for your help, guidance or example code.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,858
Messages
6,121,956
Members
449,057
Latest member
FreeCricketId

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top