0

I need an excel formula that if a number in cell A1 is 1,2 or 3 then put number 8 in cell A2. If not leave blank.

I tried a bunch of formulas but I don't know what this one would be called. Sounds like a simple formula but I have alot to learn about Excel.

3
  • 1
    Try =IF(ISNA(MATCH(A1,{1;2;3},0)),"",8). In MS365 =IF(ISNA(XMATCH(A1,{1;2;3})),"",8) or =IF(ISNA(XMATCH(A1,SEQUENCE(3))),"",8).
    – VBasic2008
    Commented Jul 7 at 5:42
  • 2
    I think ISNA(MATCH(A1,{1;2;3},0)) is the same as =NOT(OR(A1={1;2;3})
    – rachel
    Commented Jul 7 at 6:55
  • 2
    @rachel You're right, I'm needlessly taking out the big guns i.e. =IF(OR(A1={1;2;3}),8,"") works just fine.
    – VBasic2008
    Commented Jul 7 at 7:19

3 Answers 3

1
=IF(OR(A1=1, A1=2, A1=3), 8, "")

This formula checks if the value in cell A1 is 1, 2, or 3. If it is, it places the number 8 in cell A2. If it's not, it leaves cell A2 blank.

1
  • Unfortunately none of these formulas worked 😕 Commented Jul 7 at 8:57
1

Try one of the following formula-

=IF((A1>=1)*(A1<=3),8,"")
=(A1>=1)*(A1<=3)*8

enter image description here

0

Since you mentioned that none of them worked, could you try this:

=IFERROR(IF(OR(0 + TRIM(A1) ={1,2,3}),8,""),"")
  • In case of these are numbers surrounded by spaces, TRIM to strip them
  • 0 + to convert to a number (-- is also used very often)
  • IFERROR is to handle error from the previous step
  • After getting a number, comparing it {1,2,3} results in TRUE/FALSE accordingly
  • In the example below, numbers are entered as text in D1-F1

Formula and result

1
  • Thanks for all the help! It turns out it wasn't the formula that was the problem. This formula worked-=IF(OR(A1=1, A1=2, A1=3), 8, "") Problem was that the cell was formatted for text instead of number!! Commented Jul 8 at 4:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.