• Status: Solved
• Priority: Medium
• Security: Public
• Views: 236

# Excel if/then

If I have a letter in cell A1, and want a corresponding number to go in A2, what would my formula be?

I would like the number 1 for A OR F; 2 for B OR G; 3 for C OR H; 4 for D OR J

Is it practical to use if/then?  What other formula could I use?
0
• 3
1 Solution

Commented:
This should work
``````=IF(OR(A1="A",A1="F"),1,IF(OR(A1="B",A1="G"),2,IF(OR(A1="C",A1="H"),3,IF(OR(A1="D",A1="J"),4,))))
``````
0

Commented:
Another good option would to use a reference table placed somewhere else and Assign values by letter.  Then you could just do a lookup on the reference table.  I think I would use that approach as it's much cleaner if you ever need to add letters.
0

Commented:
Here's what I played with.
IfthenAlternatives.xlsx
0

EngineerCommented:
If it is always 2 at a time then you can use something like

=INT(MATCH(A1,{"";"A";"F";"B";"G";"C";"H";"D";"J"},0)/2)
0

Author Commented:
Great formula, easy to use, especially if there are only a few options.  The lookup is also an option.

Thanks!
0

## Featured Post

• 3
Tackle projects and never again get stuck behind a technical roadblock.