=IF(AE344=AH344,"1","2")

Lets assume thats in AE500.

Next to this I want to write a formula that tells me the value in this cell. So for example next to the 1 or 2 above, in the adjacent cell, I want to write a formula that will give me the value in AE344.

This gets complicated though because I cant drag the formulas downwards for reason too complex to explain. So ideally I'd write a formula in AF500, which would look at AE500, look at the text in the spaces of 5-9 (which is AE344) and give me the value.

Is this possible?