Return a code based off post code

jasonoakley

New Member
Joined
Jan 7, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have a list of codes that relate to post codes, e.g. if a post code contains B2, B3, B10 etc then the code is B 1-1 if it contains B1, WS10, WV4 etc then the code is B 1-2 and so.

I'm trying to get it so when I type in the post code into the first cell, the next cell automatically populates with the code, I've tried lookup and if formulas but I can't seem to get it to allow me to do multiple arguments and return different values.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
One way would be to use the sheet change event:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo errHandler
Application.EnableEvents = False
Select Case Ucase(Target)
    Case "B2", "B3", "B10"
        Target.Offset(0, 1) = "B 1-1"
    Case "B1", "WS10", "WV4"
        Target.Offset(0, 1) = "B 1-2"
    'add other cases
End Select

exitHere:
Application.EnableEvents = True
Exit Sub

errHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume exitHere
        
End Sub
Ucase should make it work even if you type in b1 instead of B1.
 
Upvote 0
Try this.
In a table you put the codes and post codes.
Then you use the vlookup function

varios 07ene2024.xlsm
ABCDEFG
1CodesPost Code
2B10B 1-1B2B 1-1
3WS10B 1-2B3B 1-1
4B2B 1-1B10B 1-1
5b1B 1-2B1B 1-2
6WS10B 1-2
7WV4B 1-2
Hoja6
Cell Formulas
RangeFormula
B2:B5B2=VLOOKUP(A2,F:G,2,0)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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