Q:

Using IF, AND, and OR statements to not repeat code in Excel

I'm trying to figure out the most efficient way to use IF statements in excel. I know what I want my code to look like if it was say, Python, but I'm struggling with it in excel.
Heres the code I have in excel, and it works and does what I want:
=IFS((AND(B4="Fall", C4="Triple")), 2190, (AND(B4="Fall", C4="Double")), 2731, (AND(B4="Fall", C4="Single")), 3175,
 AND(B4="Winter", C4="Triple"), 1902,  AND(B4="Winter", C4="Double"), 2372,  AND(B4="Winter", C4="Single"), 2757,
  AND(B4="Spring", C4="Triple"), 1671, AND(B4="Spring", C4="Double"), 2084, AND(B4="Spring", C4="Single"), 2423,
 ISBLANK(B4), "Pick A quarter", ISBLANK(C4), "Pick A dorm style")

As you can see, There is lots of stuff that is repeated and is unnecessary. It makes it hard to read, and long to type. Especially since I have to do essentially the same thing with very slight changes to the second parameter in the AND() statements and the results.
Here is what I would like the code to be equivalent to.
B4 = "Fall"
C4 = "Double"

if (B4=="Fall"):
    if (C4 == "Triple"):
        print(2190)
    if (C4 == "Double"):
        print(2731)
    if (C4 == "Single"):
        print(3175)
elif (B4 == "Winter"):
    if (C4 == "Triple"):
        print(1902)
    if (C4 == "Double"):
        print(2372)
    if (C4 == "Single"):
        print(2757)
elif (B4 == "Spring"):
    if (C4 == "Triple"):
        print(1671)
    if (C4 == "Double"):
        print(2084)
    if (C4 == "Single"):
        print(2423)
else:
    print("...")

Now admittedly, this code still isn't great and it seems like there would be a much better, shorter more efficient way to write this out. But it gets the point across. (If there was a way to create this in python and change excel cells from python code, that'd be cool to). Anyone have some ideas?

A:

The most common Excelsolution is having a helper table and using INDEX - MATCH.
Example:

Formula in B5:
=INDEX($F$3:$H$5,MATCH(B4,$E$3:$E$5,0),MATCH(C4,$F$2:$H$2,0))

The helper table could be on a separate sheet which could be hidden. So it would be not visible.

A:

You can call a VBA function that resides within the workbook from within a formula, passing the two input cells as parameters.
Add a Module in the VBA IDE with the following code:
Function GetRate(season As String, size As String)
    If season = "Fall" Then
        If size = "Triple" Then
            GetRate = 2190
        ElseIf size = "Double" Then
            GetRate = 2731
        ElseIf size = "Single" Then
            GetRate = 3175
        End If
    ElseIf season = "Winter" Then
        If size = "Triple" Then
            GetRate = 1902
        ElseIf size = "Double" Then
            GetRate = 2372
        ElseIf size = "Single" Then
            GetRate = 2757
        End If
    ElseIf season = "Spring" Then
        If size = "Triple" Then
            GetRate = 1671
        ElseIf size = "Double" Then
            GetRate = 2084
        ElseIf size = "Single" Then
            GetRate = 2423
        End If
    Else
        GetRate = "..."
    End If
End Function

Note: I literally just quickly translated your python code to VBA. I won't delve into the quality of said code since it seems out of scope for this question. (It's not bad as such but there could be improvements.)
Call the function in a cell formula and pass two cell references as parameters:
=GetRate(A1, B1)
The workbook must be saved with the file type "Excel Macro-Enabled Workbook (*.xlsm)". It will warn you if you don't, and you will lose the module and code if you ignore the warning and save as a normal .XLS file.

