Excel-如何从某些值开始find平均值?

在这里input图像说明

看上面的图片,我想知道如何find一个符合某些标准的数字开始平均? 例如,给定范围J3:Q3,如果数字大于50(在本例中为L3:Q3),我将如何开始find平均值?

您可以在Worksheet中的VBA中添加一个自定义函数,您可以从工作表中调用它。

在您的Excel工作表中,您需要键入

=Average_Cells(first_cell_for_average, value_above) 

first_cell_for_average – 你可以放A3,这个函数会处理剩下的事情

value_above =在你的文章中是50,你可以稍后修改它为你想要的任何值。

function代码:

 Public Function Average_Cells(ByRef first_Cell As Range, larger_Than As Long) As Double ' Row 3 in your post last_col = ActiveSheet.Cells(3, ActiveSheet.Columns.count).End(xlToLeft).Column first_Col = first_Cell.Cells(1, 1).Column For col = first_Col To last_col If Cells(3, col).Value > larger_Than Then GoTo Exit_For End If Next Exit_For: Average_Cells = Application.WorksheetFunction.Average(Range(Cells(3, col), Cells(3, last_col))) End Function 

Hack-y方法:

用J4填写

 =IF(J3>50, J3, '') 

然后复制到Q4。

然后用J5填写

 =AVERAGE(J4:Q4)