Min of 5 cells before different from 0

rama1234

New Member
Joined
Apr 25, 2016
Messages
5
Hello everyone, thanks for your time in advance.
My first column are numbers, for example:
A1: Column 1
A2: 10
A3: 2
A4: 10
A5: 10
A6: 5
A7: 0
A8: 0
A9: 0
A10: 5
A11: 5
A12: 5
...
Then in my second column calculates the minimum of 5 cells before that are different from 0.
For example the cell B6 is the minimum of A6-A5-A4-A3-A2 different from 0, so is 2... But the cell B9 is also the minimum of A6-A5-A4-A3-A2 as I want the minimum of 5 numbers that are different from 0 and I don't know how to do it.
My formula in B9 is:
{=IF(ROW(A9)<=5;0;MIN(IF((INDEX(A:A;ROW(A10)-5):A9)<>0;(INDEX(A:A;ROW(A10)-5):A9))))}

My desired results in column 2 are:
B1: Column 2
B2: 0
B3: 0
B4: 0
B5: 0
B6: 2
B7: 2
B9: 2
B10: 2
B11: 5
B12: 5

Thanks a lot
 

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,219
Office Version
365
Platform
Windows
Hi, here is one option you can try.

<b>Excel 2013/2016</b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">2</td><td style="text-align: right;;">10</td><td style="text-align: right;background-color: #FFFF00;;">0</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">3</td><td style="text-align: right;;">2</td><td style="text-align: right;;">0</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style="text-align: right;;">10</td><td style="text-align: right;;">0</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">5</td><td style="text-align: right;;">10</td><td style="text-align: right;;">0</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">6</td><td style="text-align: right;;">5</td><td style="text-align: right;;">2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">7</td><td style="text-align: right;;">0</td><td style="text-align: right;;">2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">8</td><td style="text-align: right;;">0</td><td style="text-align: right;;">2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">9</td><td style="text-align: right;;">0</td><td style="text-align: right;;">2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">10</td><td style="text-align: right;;">5</td><td style="text-align: right;;">2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">11</td><td style="text-align: right;;">5</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">12</td><td style="text-align: right;;">5</td><td style="text-align: right;;">5</td></tr></tbody></table><p style="width:4.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet1</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Array Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B2</th><td style="text-align:left">{=IF(<font color="Blue">COUNTIFS(<font color="Red">A$2:A2,"<>0"</font>)<5,0,MIN(<font color="Red">IF(<font color="Green">ISNUMBER(<font color="Purple">MATCH(<font color="Teal">ROW(<font color="#FF00FF">A$2:A2</font>),LARGE(<font color="#FF00FF">IF(<font color="Navy">A$2:A2<>0,ROW(<font color="Blue">A$2:A2</font>)</font>),{1,2,3,4,5}</font>),0</font>)</font>),A$2:A2</font>)</font>)</font>)}</td></tr></tbody></table><b>Entered with Ctrl+Shift+Enter.</b> If entered correctly, Excel will surround with curly braces {}.
<b>Note: Do not try and enter the {} manually yourself</b></td></tr></table><br />
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,752
Hi

Another option, also array formula:

=IFERROR(MIN(IF(ROW($A$2:A2)>=LARGE(IF(A$2:A2<>0,ROW(A$2:A2)),5),IF($A$2:A2>0,$A$2:A2))),0)
 

rama1234

New Member
Joined
Apr 25, 2016
Messages
5
Thanks, it outputs the desired results but I want to use the minimum of 5 days as variable so I can change it to say 10, 20, 50... Maybe you know how to do it,
Thanks
 

rama1234

New Member
Joined
Apr 25, 2016
Messages
5
Wow! Thanks, this is what I was lloking for. Thanks both for your replies
 

Forum statistics

Threads
1,082,359
Messages
5,364,916
Members
400,815
Latest member
Joaquin Phoenix

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