# Min of 5 cells before different from 0

#### rama1234

##### New Member
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
Hi, here is one option you can try.

<b>Note: Do not try and enter the {} manually yourself</b></td></tr></table><br />

#### pgc01

##### MrExcel MVP
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
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
Wow! Thanks, this is what I was lloking for. Thanks both for your replies

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

### 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...
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...