Selected Answer
I think you may be looking for a nested IF statement. Here is what it would look like.
=IF(E3="Buy",C3-B3,IF(E3="Sell",C3-D3,""))
In the attached workbook the formula is in F3 of Solution 1. As you see there, I combined your columns E:F into one, with a drop-down to select "Buy" or "Sell". As you change the selected action the total in column F is computed differently.
EDIT 07 Mar 2021 ======================
Your updated question points to the need for the Buy/Sell decision to be in 2 columns. That appears counter to your own logic by which yiou correctly wish to combine the differences into a single column. With your updated question the problem shifts to Sheet 2 where you appear to enable two user mistakes.
- The user may mis-spell his decision
- The user may enter a decision in both columns.
Both sources of error can be eliminated by entering the decision in a single column as demonstrated in Sheet2 (2) in the attached workbook. You could then more easily convey that decision to Sheet1 as shown in my sheet Solution 2.
The formula you are asking about remains the same as it was in Solution 1.