largest, smallest, 2nd largest & 2nd smallest

hsandeep

Well-known Member
Joined
Dec 6, 2008
Messages
950
Posted on https://www.excelforum.com/excel-general/1294641-largest-smallest-2nd-largest-and-2nd-smallest-2.html#post5221789

but could not got complete answer

I need 4 formulae for: largest, smallest, 2nd largest (smaller than largest & non duplicate of largest) & 2nd smallest (larger than smallest & non duplicate of smallest) from B3:L3 (contiguous columns) in N3, O3, P3, Q3

Conditions #1 : If all values in B3:L3 are zero 0 or null, then all 4 formulae should give answers as blank.
Conditions #2 : largest & 2nd largest cannot be same, similarly smallest & 2nd smallest cannot be same.

Example: If B3=500, C3=600, D3=600, E3=600, F3=600, G3=600, H3=600, I3=600, J3=600, K3=600, L3=600 then largest=600, smallest=500, 2nd largest=blank, 2nd smallest=blank

Conditions #3 : Any of the 4 answers cannot be zero. This condition #3 requires more clarifications which are:

Example: If B3=0, C3=800, D3=-800, E3=-20, F3=-9, G3=-2, H3=-1, I3=0, J3=0, K3=0, L3=0 then largest=800, smallest=-800, 2nd largest=-1, 2nd smallest=-20

Conditions #4 : If all the values are same (but <>0 or <>””), then Example: If B3=-5, C3=-5, D3=-5, E3=-5, F3=-5, G3=-5, H3=-5, I3=-5, J3=-5, K3=-5, L3=-5 then largest=-5, smallest=-5, 2nd largest=blank, 2nd smallest=blank

Note: 2nd largest & 2nd smallest can be same

Example: If B3=0, C3=800, D3=-8, E3=0, F3=-9, G3=0, H3=0, I3=0, J3=0, K3=0, L3=0 then largest=800, smallest=-9, 2nd largest=-8, 2nd smallest=-8
How to accomplish?
Thanks

BCDEFGHIJKLMNOPQ
2LargestSmallest2nd Largest2nd Smallest
300000000000
4
5500600600600600600600600600600600600500600600
60800-800-20-9-2-10000800-800-1-20
7-5-5-5-5-5-5-5-5-5-5-5
80800-80-9000000800-9-8-8
9803210203010500-980-980-95010
10800800000000000800800

<tbody>
</tbody>
Correct answer for P5="",Q5=""
Correct answer for N7=-5,O7=-5
 
Last edited:

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,790
Office Version
2007
Platform
Windows
Why P9 = 50 (Should it be 80?)
Why Q9 = 10 (Should it be -9?)

Why Q8 = -8 (Should it be ""?)
 

hsandeep

Well-known Member
Joined
Dec 6, 2008
Messages
950
Why P9 = 50 (Should it be 80?)P9 should be 50 & not 80 since non duplicate is required
Why Q9 = 10 (Should it be -9?)Q9 should be 10 & not -9 since non duplicate is required
Why Q8 = -8 (Should it be ""?) Q8 should be -8 & not “” since 2n dlargest (<>), <>””)
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,357
Office Version
2013
Platform
Windows
Hi, hsandeep
I might have an idea, using UDF. Is that ok with you?
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
7,149
Office Version
2019
Platform
Windows
This looks like it works, note that the fomulas in P3 and Q3 must be array confirmed with Ctrl Shift Enter.

N3 =IFERROR(AGGREGATE(14,6,1/(1/B3:L3),1),"")
O3 =IFERROR(AGGREGATE(15,6,1/(1/B3:L3),1),"")
P3 =IF(SUM(IFERROR(1/COUNTIF(B3:L31,1/(1/(B3:L3))),0))=2,"",IFERROR(AGGREGATE(14,6,1/(1/B3:L3),1+COUNTIF(B3:L3,N3)),""))
Q3 =IF(SUM(IFERROR(1/COUNTIF(B3:L31,1/(1/(B3:L3))),0))=2,"",IFERROR(AGGREGATE(15,6,1/(1/B3:L3),1+COUNTIF(B3:L3,N3)),""))
 

hsandeep

Well-known Member
Joined
Dec 6, 2008
Messages
950
This looks like it works, note that the fomulas in P3 and Q3 must be array confirmed with Ctrl Shift Enter.
the 4 formulas are not working..
largest: For B3=500 & C3:L3=600; N3 should be 600 (formula gives answer as "");
smallest: For B3=500 & C3:L3=600; O3 should be 500 (formula gives answer as "")
Even 2nd largest & 2nd smallest are not working
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
7,149
Office Version
2019
Platform
Windows
The formulas work fine, the sample table that you provided is not consistent with your description of the problem.

In the example that you proved in post 1, B3:L3 =0, B5 = 500 & C5:L5 = 600

With the above, all 4 results in N3:Q3 = "" because there are no non 0 values in the row.
N5 = 600, O5 = 500, P5 = "", Q5 = "" which is exactly what you say it should be.

If you want a better answer, ask a better question.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,790
Office Version
2007
Platform
Windows
[Delete
 
Last edited:

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,790
Office Version
2007
Platform
Windows
Why P9 = 50 (Should it be 80?)P9 should be 50 & not 80 since non duplicate is required
Why Q9 = 10 (Should it be -9?)Q9 should be 10 & not -9 since non duplicate is required
Why Q8 = -8 (Should it be ""?) Q8 should be -8 & not “” since 2n dlargest (<>), <>””)
Answer in rows 5, 8 and 10 you have duplicate values. you can explain?
 

Forum statistics

Threads
1,081,868
Messages
5,361,775
Members
400,656
Latest member
seban

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top