You can put this formula in cell B1, so that excel will count from range A1:A5 to see whether it has A or B. If either A or B is found within the range, it will return 1, otherwise it will return 2.
P.S. remove the symbol semi-colon (;) from the equation, for some reason it appears above. The correct formula should not have that semi-colon...........