Vlookup based on contents of a cell

geordie_ben

Board Regular
Joined
Jul 27, 2009
Messages
122
I've gotten a list of post codes and their counties.

This is how the data is presented:

Postcode areaPostcode districtsPost townFormer postal county
ABAB10, AB11, AB12, AB15, AB16,
AB21, AB22, AB23, AB24, AB25,
AB99non-geo
Aberdeen<small style="font-size: 11.9px;">(Aberdeenshire)</small>

<thead>
</thead><tbody>
</tbody>
I need to do some type of lookup (I think), where the first part of a full post code being AB22 would show Aberdeenshire

Is there a type of formula I could use to do this?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi, you could extract the postcode area from a full postcode with a formula like this:


Excel 2013/2016
AB
1Full postcodePostcode area
2AB22 0AAAB
Sheet1
Cell Formulas
RangeFormula
B2=LEFT(A2,AGGREGATE(15,6,FIND({0,1,2,3,4,5,6,7,8,9},A2),1)-1)


You could then do a standard VLOOKUP() to the get post town or county.
 
Upvote 0
Hi

Thanks for the super quick reply

The above was a snippet of every post code in the UK

Would you formula still work?

I can't do the lookup on "AB" in the above example as some Postcode Areas have more than County inside them
 
Upvote 0
The above was a snippet of every post code in the UK

Hi, a slightly bigger snippet, along with a few examples of the inputs and expected results be helpful. But pending that - here's another stab.


Excel 2013/2016
ABCDEFG
1Postcode areaPostcode districtsPost townFormer postal countyFull postcodetown
2ABAB10, AB11, AB12, AB15, AB16, AB21, AB22, AB23, AB24, AB25, AB99non-geoAberdeen(Aberdeenshire)AB22 0AAAberdeen
Sheet1
Cell Formulas
RangeFormula
G2=VLOOKUP("*"&LEFT(F2,FIND(" ",F2&" ")-1)&"*",B:C,2,0)
 
Upvote 0
Hi

The list of information is from here - https://en.wikipedia.org/wiki/List_of_postcode_districts_in_the_United_Kingdom

This is a decent snippet:

BB1, B2, B3, B4, B5, B6, B7, B8, B9,
B10, B11, B12, B13, B14, B15, B16, B17, B18, B19,
B20, B21, B23, B24, B25, B26, B27, B28, B29,
B30, B31, B32, B33, B34, B35, B36, B37, B38,
B40, B42, B43, B44, B45, B46, B47, B48,
B99non-geo
Birmingham<small style="font-size: 11.9px;">(West Midlands)</small>
BB49,
B50
AlcesterWarwickshire
BB60, B61BromsgroveWorcestershire
BB62, B63HalesowenWest Midlands
BB64Cradley HeathWest Midlands
BB65Rowley RegisWest Midlands
BB66, B67SmethwickWest Midlands
BB68, B69OLDBURYWest Midlands
BB70, B71West BromwichWest Midlands
BB72, B73, B74, B75, B76Sutton ColdfieldWest Midlands
BB77, B78, B79TAMWORTHStaffordshire
BB80STUDLEYWarwickshire
BB90, B91, B92, B93, B94SolihullWest Midlands

<tbody>
</tbody>
I have a list of customer post codes, and I need to establish which County they're in, which is Column D in the above example

Example:

Postcode is B75 1AZ

I've done a text to columns, delimited on space to get the first part of the Post Code (I've manually checked them and they're all good - phew!)

The formula would then bring back the County as West Midlands

Hopefully this helps
 
Upvote 0
I've done a text to columns, delimited on space to get the first part of the Post Code

Hi, you can try this:


Excel 2013/2016
ABCDEFG
1BB1, B2, B3, B4, B5, B6, B7, B8, B9,B10, B11, B12, B13, B14, B15, B16, B17, B18, B19,B20, B21, B23, B24, B25, B26, B27, B28, B29,B30, B31, B32, B33, B34, B35, B36, B37, B38,B40, B42, B43, B44, B45, B46, B47, B48,B99non-geoBirmingham(West Midlands)
2BB49,B50AlcesterWarwickshireB75West Midlands
3BB60, B61BromsgroveWorcestershire
4BB62, B63HalesowenWest Midlands
5BB64Cradley HeathWest Midlands
6BB65Rowley RegisWest Midlands
7BB66, B67SmethwickWest Midlands
8BB68, B69OLDBURYWest Midlands
9BB70, B71West BromwichWest Midlands
10BB72, B73, B74, B75, B76Sutton ColdfieldWest Midlands
11BB77, B78, B79TAMWORTHStaffordshire
12BB80STUDLEYWarwickshire
13BB90, B91, B92, B93, B94SolihullWest Midlands
Sheet1
Cell Formulas
RangeFormula
G2=LOOKUP(2,1/(ISNUMBER(SEARCH(F2&",",$B$1:$B$999&","))),$D$1:$D$999)
 
Upvote 0
Out of interest, why did you change the formula?

Hi, I realised that the VLOOKUP() with the wildcards is not robust. It would match B2 with B22 if B22 happened to occur in a row before B2 for example.
 
Upvote 0

Forum statistics

Threads
1,214,416
Messages
6,119,384
Members
448,889
Latest member
TS_711

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