I tried it this way:
This code goes in the worksheet's VBA
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Dim lstObj As ListObject
Dim rColumn As Range
Dim sDate As Date
Dim eDate As Date
Dim xrow As Long
' Get the table reference
Set lstObj = ActiveSheet.ListObjects("V_Feed")
' Get the column reference
Set rColumn = lstObj.ListColumns("Ate it?").DataBodyRange
If Target.Column <> rColumn.Column Then Exit Sub
Application.EnableEvents = False
sDate = 0: eDate = 0
For xrow = 1 To lstObj.DataBodyRange.Rows.Count
If LCase(rColumn(xrow).Value) = "no" Then
lstObj.DataBodyRange.Cells(Target.Row, 3).Value = 0
ElseIf LCase(rColumn(xrow).Value) = "yes" And sDate = 0 Then
sDate = lstObj.DataBodyRange.Cells(xrow, 1).Value
ElseIf LCase(rColumn(xrow).Value) = "yes" Then
eDate = lstObj.DataBodyRange.Cells(xrow, 1).Value
lstObj.DataBodyRange.Cells(xrow, 3).Value = WorksheetFunction.Days360(sDate, eDate)
sDate = lstObj.DataBodyRange.Cells(xrow, 1).Value
End If
Next xrow
Application.EnableEvents = False
End Sub
For the average I set the formula as follows:
=AVERAGEIFS(V_Feed[Interval],V_Feed[Ate it?],"yes")
Bookmarks