Populate Based on Criteria

kumara_faith

Well-known Member
Joined
Aug 19, 2006
Messages
922
Office Version
  1. 365
Hi,

I have the following table:

Stock Market Buy Sell Model.xlsx
KLMNO
2DatePrice% DifferenceBuySell
31/1/2021100-3%100
42/1/20211055%105
53/1/202195-10%95
64/1/202111521%115
75/1/202185-26%85
86/1/202112041%120
97/1/2021119-1%
108/1/2021118-1%
119/1/2021117-1%
1210/1/2021115-2%115
1311/1/202185-26%
1412/1/202112041%120
1513/1/2021105-13%105
1614/1/202195-10%
1715/1/202111521%115
Sheet1
Cell Formulas
RangeFormula
M4:M17M4=(L4/L3)-1


I am trying to build a formula in column N and column O as follows:

1) If column M is down by 2% or more, then we will buy 1 unit of the product for the price in column L
2) If column M is up by 2% or more, then we will sell 1 unit of the product for the price in column L
3) We can only buy and sell once. Which means if we have bought previously, we will not buy again even when the price is down by 2% or more until we have sold. The same applies for sell as well

The correct result is as per the table above. I tried using the following IF formula but it does not seems to work.

Excel Formula:
=IF(M3<=-2%,L3,"")

Appreciate all the help.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Maybe...
Note that I got a different result on row 12 (-1.71% is not less than or equal to -2%)

Pasta1
KLMNO
1
2DatePrice% DifferenceBuySell
301/01/2021100-3,00%100 
402/01/20211055,00% 105
503/01/202195-9,52%95 
604/01/202111521,05% 115
705/01/202185-26,09%85 
806/01/202112041,18% 120
907/01/2021119-0,83%  
1008/01/2021118-0,84%  
1109/01/2021117-0,85%  
1210/01/2021115-1,71%  
1311/01/202185-26,09%85 
1412/01/202112041,18% 120
1513/01/2021105-12,50%105 
1614/01/202195-9,52%  
1715/01/202111521,05% 115
Plan4
Cell Formulas
RangeFormula
N3:N17N3=IF(AND($M3<=-0.02,IFERROR(MATCH(9.99E+307,N$2:N2),0)<=IFERROR(MATCH(9.99E+307,O$2:O2),0)),$L3,"")
O3:O17O3=IF(AND($M3>=0.02,IFERROR(MATCH(9.99E+307,O$2:O2),0)<=IFERROR(MATCH(9.99E+307,N$2:N2),0)),$L3,"")
M4:M17M4=(L4/L3)-1


Hope this helps

M.
 
Upvote 0
Solution
Hi Marcelo,

That worked. Thank you and appreciate your valuable time and patience. Have a great day ahead.?
 
Upvote 0
Hi Marcelo,

My apologies. I have a further query on the solution. I have the formula in the input sheet below:

Buy and Hold.xlsx
BCDEF
4DatePrice% DifferenceBuySell
59/5/199623.2  
610/5/1996243.45% 24
713/5/199623.9-0.42%  
814/5/199623.6-1.26%  
915/5/199623.2-1.69%  
1016/5/199622.6-2.59%22.6 
1117/5/199622.80.88%  
1220/5/199622.5-1.32%  
1321/5/199622.60.44%  
1422/5/199622-2.65%  
1523/5/199622.10.45%  
1624/5/199621.6-2.26%  
1728/5/199621.2-1.85%  
1829/5/199620.8-1.89%  
1930/5/199620.5-1.44%  
2031/5/199620.4-0.49%  
213/6/199620.1-1.47%  
224/6/199621.46.47% 21.4
Sheet1
Cell Formulas
RangeFormula
E5:E22E5=IF(AND($D5<=-0.02,IFERROR(MATCH(9.99E+307,E$4:E4),0)<=IFERROR(MATCH(9.99E+307,F$4:F4),0)),$C5,"")
F5:F22F5=IF(AND($D5>=0.02,IFERROR(MATCH(9.99E+307,F$4:F4),0)<=IFERROR(MATCH(9.99E+307,E$4:E4),0)),$C5,"")
D6:D22D6=(C6/C5)-1


1) Is there a way to modify to the formula to start at buy and not sell ? In the table above the formula populates the results for sell first.
2) In cell E10, the formula buys at price 22.6. Then in cell F22, the formula sells at price 21.4. Is there a way to modify the formula to sell not only if the changes in price is more than 2% (existing criteria) but also higher than the buy price ?

Appreciate all the help.
 
Upvote 0
Hi,

I have cross post here:

 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top