How do I calculate an average of the last 5 nonblank cells in a ro
Use this custom function
call with
=AverageLast5("Q") where Q is the column
Note: if there are less than 5 items in the row it will average only the
number of cells with values.
Function AverageLast5(MyCol As String)
LastRow = Cells(Rows.Count, MyCol).End(xlUp).Row
RowCount = LastRow
CellCount = 0
Total = 0
Do While (RowCount 0) And (CellCount < 5)
If Not IsEmpty(Cells(RowCount, MyCol)) Then
Total = Total + Cells(RowCount, MyCol)
CellCount = CellCount + 1
End If
RowCount = RowCount - 1
Loop
AverageLast5 = Total / CellCount
End Function
" wrote:
I am trying to average only the last 5 nonblank values in a row of
cells. Is this possible?
|