Selected Answer
If Madrid should become MAD, then use a formula like this pointing to the cell with Madrid:
=UPPER(LEFT(A1,3))
If you want to search for Madrid using the code MAD then you need to use Vlookup. Maybe something like this:
=VLOOKUP(A1,F1:G5,2,FALSE)
A1 is the cell with the code in it.
F1:G5 should be the table that lists the codes along with the full names. MAKE SURE the codes are in the left most column of this range, in this case, in column F.
2 means that the full names will be in the second column of the table in the range F1:G5, which in this case means they will be in column G.
FALSE means to only return a result if an exact match is found.