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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,215,139
Messages
6,123,259
Members
449,093
Latest member
Vincent Khandagale

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