find last value before limit in unsorted list

hmmm...

Board Regular
Joined
Feb 24, 2003
Messages
104
Hi,

Let's say these cells contain these values:

cell a1=212
cell a2=324
cell a3=488
cell a4=538
cell a5=498
cell a6=444


I have a "threshold" value of 500.

I would like Excel to return the highest value that occurs before (in the array order) the threshold. (In this case the value would be 488). I need to keep the list unsorted. It would be best if I could find a formula (rather than VBA solution) for the sheet that I am using.

Any ideas? Thank you!
 
Rick, thank you for your reply too. Yours works on my first example too, of course; and again I'm surprised that I don't see yet how it does. Can it work with the #NAs in there? So far I can't figure that out. Thanks!

No, those #N/A's change the problem completely from the one you presented to us early. More than likely, Aladin will pop in with a solution before I do, but I'll be thinking about it. For future questions you may ask... do not simplify your data or the question itself for us, all that will get you (as in the present case) is great answers for a question you do not actually have and which you do not really care about.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
No, those #N/A's change the problem completely from the one you presented to us early. More than likely, Aladin will pop in with a solution before I do, but I'll be thinking about it. For future questions you may ask... do not simplify your data or the question itself for us, all that will get you (as in the present case) is great answers for a question you do not actually have and which you do not really care about.
Okay, I think I have a solution. Give this array-entered** formula a try...

=INDEX(A:A,MAX(IF(ROW(A1:A18)< MIN(IF(NOT(ISERROR(A1:A18)),IF(A1:A18>=500,ROW(A1:A18)))),IF(NOT(ISERROR(A1:A18)),ROW(A1:A18)))))<min(if(not(iserror(a1:a18)),if(a1:a18><min(if(not(iserror(a1:a<font color="#FF0000">

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.

I am still betting on Aladin (or even one of the other volunteers) coming in with a better formula, but until then, the above should work for you (but come back to this thread every now and then to see if a better formula has been posted).</min(if(not(iserror(a1:a</min(if(not(iserror(a1:a18)),if(a1:a18>
 
Upvote 0
Sorry to have led you two astray by leaving out the details--I was trying to make the problem simpler to pose, but I can see I shouldn't have done that!

Rick, your solution works, and I can even understand that one: you are looking for the maximum row number that both (is less than the row containing the first <=500 value) and also (does not contain an error code). Nice!

Thank you both for your solutions and I will pick the first two apart so I know how they work.
 
Upvote 0
Aladin, Thank you for your reply. I expected I'd be able to decipher a reply better than I can yours. Your formula works for the example I gave, and I'll dissect it until I understand it, but that might take a while. Meanwhile, my data actually look like this:

cell a1=#N/A
cell a2=#N/A
cell a3=212
cell a4=#N/A
cell a5=#N/A
cell a6=#N/A
cell a8=324
cell a9=#N/A
cell a10=488
cell a11=#N/A
cell a12=#N/A
cell a13=538
cell a14=#N/A
cell a15=498
cell a16=#N/A
cell a18=#N/A
cell a19=444
cell a20=#N/A

I thought I'd be able to plug IFNA=FALSE into any formula in a reply, but apparently I should have put in this detail, since I can't see yet where I would plug this into your formula. Thanks!

Assumptions:

(1) when the data contains the threshold value, return that value.
(2) when no value >= threshold, return the value closest to threshold.
(3) otherwise return the last value that occurs before the first value > threshold

The earlier formula obeys the above specification in a range which is not infested with #N/A's. What follows is meant to replicate the earlier fomula for a range that also house #N/A's. Rick's proposals differ I believe w.r.t. the first two points.

Define BigNum as referring to:

=9.99999999999999E+307

Control+shift+enter, not just enter:
Rich (BB code):
=IFERROR(LOOKUP(BigNum,A1:INDEX(A1:A18,MATCH(FALSE,IF(ISNUMBER(A1:A18),
  IF(A1:A18<=C1,ROW(A1:A18)-ROW(A1)+1),#N/A),0)-1)),
  INDEX(A1:A18,MATCH(MIN(ABS(IF(ISNUMBER(A1:A18),A1:A18,BigNum)-C1)),
  ABS(A1:A18-C1),0)))
 
Upvote 0
Aladin,
I'm not sure what I did to ensue such hostility...please clear this up for me so I don't make such a mistake again. I also don't understand what 'robust' means in the context above or to which flaw you refer in the formula. I do like the 'question under question' phrase. Let me know.

No need to jump to such a conclusion. A formula with ROW(A1) is risky. Try to add/insert rows in front of the formula with that ROW bit and observe the results.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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