开发者

How to write formula in Excel for my requirement

my requirement as follows:

if a5 = 'a' then b5 = 1 
if a5 = 'b' then b5 = 2
if a5 = 'c' then b5 = 3
if a5 = 'd' then b5 = 4
if a5 = 'e' then b5 = 5
else enter correct letter

total no. of conditions are more than 5 as of now and then i need to put default msg for this like 'ENTER CORRECT LETTER 开发者_高级运维'


Excel's IF statement is IF(condition, trueValue, FalseValue). You can nest them to accomplish if-else chains via IF(condition1, trueValue, IF(elseCondition, elseTrue, defaultValue))

Formulas are entered in a cell in Excel by starting the cell's contents with an equals sign.

Conditions of equality in Excel use single equals comparison, not double equals.

There are other ways to approach the problem; if you had a range defined of valid entries, for example, MATCH would be useful for finding the position of a matching cell within that range.


 =IF(A5="a",1,
     IF(A5="b",2,
        IF(A5="c",3,
           IF(A5="d",4,
              IF(A5="e",5,"Enter Correct Letter")))))


Insert this into cell B5

=IF(OR(CODE(A5)<97,CODE(A5)>101),"ENTER CORRECT LETTER",CODE(A5)-96)


you can see example implimentation in this sheet. Let me know if it helps or you need further explanation.


=IF(ISERROR(FIND(A5,"ABCDE")),"Enter correct letter",CODE(A5)-64)

This will work with as many letters as you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜