Subtracting cells only if they have a value in Excel

I want to subtract two cells in excel but only if both cells have a value. More specifiaclly in my case the formula in cell E2 is currently =D2-C2 but I only want this to be calculated when D2 has a value. (D2=winnings, C2=stake and E2 = profit/loss. I don't want the profit loss calculated until the winnings cell is completed.)

Can anyone help please?

Steve


Solution 1:

Place the following formula in cell E2 to achieve what you want:

=IF(ISBLANK(D2),"",D2-C2)

If you want both cells to have a value:

=IF(OR(ISBLANK(D2),ISBLANK(C2)),"",D2-C2)

Solution 2:

Try this in cell E2:

=IF(AND(D2<>"",C2<>""),D2-C2,"")