Need to get average of last 10 non-zero values in a row (grows daily)

Fargol

New Member
Joined
Nov 15, 2017
Messages
2
I have a spreadsheet with hundreds of rows that grows daily. I'd like to set up a cell at the top that'll display the average of the last 10
non-zero, non-blank rows and adjust each time a new value is added. I've tried many things, all to no avail.

Thanks in advance.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
"non-zero, non-blank rows" sound like you have a complicated structure.

Are there blank rows between non-blank rows?
What is a "zero row"? A row with one zero somewhere in the row or a row where all the cells contain 0?
How many columns are in your data set? If it varies, what is the maximum?
 
Upvote 0
"non-zero, non-blank rows" sound like you have a complicated structure.

Are there blank rows between non-blank rows?
What is a "zero row"? A row with one zero somewhere in the row or a row where all the cells contain 0?
How many columns are in your data set? If it varies, what is the maximum?

Yes. some rows might be blank if I neglected to put anything in it that day. Non-zero doesn't really apply since it'll either have a number > 0, or be blank.

Let me also clarify - I currently have several hundred rows. Theoretically, there is no maximum. In each row is various data such as date and time, and three cells (consecutive columns) in each row contain the values I wish to average over the last 10 days.

It looks like this ... Columns E, F, and G are the ones I want to display the last 10 day average for. As you can see, there are blanks. So, to simplify it, three cells at the top of the sheet will
display the average for the last 3 values in E, F, and G. So E's average would be (116+110)/2, F's would be (86+88+112) / 3, and G's would be (100+108)/2.

A B C D E F G
3/7/17192.08:00 AM8:00 AM118106
3/8/17191.08:00 AM8:00 AM12594
3/9/17189.08:00 AM8:00 AM1249596
3/10/17189.08:00 AM8:00 AM120118
3/11/17190.08:00 AM8:00 AM126118
3/12/17191.08:00 AM8:00 AM 90106
3/13/17189.08:00 AM8:00 AM134 114
3/14/17190.08:00 AM8:00 AM11688116
3/15/17190.08:00 AM8:00 AM11686100
3/16/17190.08:00 AM8:00 AM11088108
3/17/17191.08:00 AM8:00 AM 112

<colgroup><col><col><col><col><col span="3"></colgroup><tbody>
</tbody>

I hope I made that clear. I'm starting to wonder if it's even possible to do what I want :)

Thanks.


"non-zero, non-blank rows" sound like you have a complicated structure.

Are there blank rows between non-blank rows?
What is a "zero row"? A row with one zero somewhere in the row or a row where all the cells contain 0?
How many columns are in your data set? If it varies, what is the maximum?

Yes. some rows might be blank if I neglected to put anything in it that day. Non-zero doesn't really apply since it'll either have a number > 0, or be blank.

Let me also clarify - I currently have several hundred rows. Theoretically, there is no maximum. In each row is various data such as date and time, and three cells (consecutive columns) in each row contain the values I wish to average over the last 10 days.

It looks like this ... Columns E, F, and G are the ones I want to display the last 10 day average for. As you can see, there are blanks. So, to simplify it, three cells at the top of the sheet will
display the average for the last 3 values in E, F, and G. So E's average would be (116+110)/2, F's would be (86+88+112) / 3, and G's would be (100+108)/2.

A B C D E F G
3/7/17192.08:00 AM8:00 AM118106
3/8/17191.08:00 AM8:00 AM12594
3/9/17189.08:00 AM8:00 AM1249596
3/10/17189.08:00 AM8:00 AM120118
3/11/17190.08:00 AM8:00 AM126118
3/12/17191.08:00 AM8:00 AM 90106
3/13/17189.08:00 AM8:00 AM134 114
3/14/17190.08:00 AM8:00 AM11688116
3/15/17190.08:00 AM8:00 AM11686100
3/16/17190.08:00 AM8:00 AM11088108
3/17/17191.08:00 AM8:00 AM 112

<colgroup><col><col><col><col><col span="3"></colgroup><tbody>
</tbody>

I hope I made that clear. I'm starting to wonder if it's even possible to do what I want :)

Thanks.
 
Upvote 0
Hello,

try this function, in A1 type =last10(A2)

Code:
Function Last10(rng As Range) As Double
Application.EnableEvents = False
col = rng.Column
lr = Cells(Rows.Count, col).End(xlUp).Row
For i = lr To 2 Step -1
If Not IsEmpty(Cells(i, col)) Then r = r + 1
    s = s + Cells(i, col)
If r = 10 Then Exit For
Next i
Last10 = s
Application.EnableEvents = True
End Function

regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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