Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Require result in one cell for two independent cell

0

Hi,

I am looking for your help in correcting If function.

Require result in one cell for two independent cell

Attached excel sheet for your reference.

Regards,

Nitil

Revision - 1

Hi,

Please refer to attached excel sheet, I require results in one cell as mention in excel sheet.

The Buy and Sell is formula based and linked from other sheet and is not manually filled.

Please help me for the solution.

Thanks & Regards,

Nitil

Answer
Discuss

Discussion

Nitil

I'm not clear (from your file) what logic you need here or what result you want. 

How is your Buy or Sell decision made? Do you buy if "Current price" is lower than "lower price" or higher than "lower" but less than "higher"? Also sell if current price is more than lower or higher price? Does the single cell need to display the decision and the price difference?

Please clarify in your Question (or revise with sample result in file)
John_Ru (rep: 6142) Mar 6, '21 at 4:41 am
Add to Discussion

Answers

0
Selected Answer

Nitil

I think Variatus gave a good answer (based on your original question/file). Looks like you've since revised your file to add a column headed "I require result like in column I" with desired results.

In that case, I think the nested IF statement from Variatus now needs one change (in bold below) to give your required result, so for cell I3 the formula becomes:

=IF(E3="Buy",C3-B3,IF(F3="Sell",C3-D3,""))
Discuss

Discussion

Thanks for selecting my Answer, Nitil
John_Ru (rep: 6142) Mar 8, '21 at 6:12 am
Add to Discussion
0

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.

  1. The user may mis-spell his decision
  2. 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.

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login