简体   繁体   English

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

[英]Excel- How to find average from from certain values onwards?

enter image description here 在此输入图像描述

Looking at the above image, I am wondering how do I find the average starting at a number that matches certain criteria? 看看上面的图像,我想知道如何从符合特定标准的数字开始找到平均值? For example, given the range J3:Q3, how would I start find the averaging after a number is greater than 50 (so in this example L3:Q3)? 例如,给定范围J3:Q3,如何在数字大于50之后开始找到平均值(在此示例中为L3:Q3)?

You can add a custome made Function in VBA in your Worksheet that you can call it from your worksheet. 您可以在工作表中添加自定义函数在VBA中,您可以从工作表中调用它。

In your Excel Worksheet you need to type 在Excel工作表中,您需要键入

=Average_Cells(first_cell_for_average, value_above)

first_cell_for_average - you can put A3, the function will handle the rest. first_cell_for_average - 你可以把A3,该函数将处理其余的。

value_above = in your post it's 50, you can modify it later to whatever value you want. value_above =在你的帖子中它是50,你可以稍后修改它到你想要的任何值。

The Function Code: 功能代码:

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 method: Hack-y方法:

Fill in J4 with 用J4填写

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

And then copy it until Q4. 然后将其复制到Q4。

Then fill in J5 with 然后填写J5

=AVERAGE(J4:Q4)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM