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

标签 excel excel-formula

enter image description here

看着上图,我想知道如何找到从符合特定条件的数字开始的平均值?例如,给定范围 J3:Q3,在数字大于 50 后我如何开始求平均值(在本例中为 L3:Q3)?

最佳答案

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

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

=Average_Cells(first_cell_for_average, value_above)

first_cell_for_average - 您可以放入 A3,该函数将处理其余的事情。

value_above = 在您的帖子中为 50,您可以稍后将其修改为您想要的任何值。

功能代码:

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

关于Excel-如何查找从某些值开始的平均值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38365178/

相关文章:

Excel - 从选项列表中匹配子字符串 - INDEX、MATCH 和 FIND 一起使用

excel - SUMIF 但对于产品?

VBA 替换不适用于 Excel 文本文档的代码

vba - VBA-如何检查字符串是否为有效的十六进制颜色代码?

excel - 从excel vba中心表到word doc

vba - 通过宏导入 CSV 时日期格式不一致

excel - 从单元格字符串中删除 HTML 标签 : excel Formula

Excel:求和公式

excel - 使用Excel中的标准差函数来实现特定标准?

excel - 如何模糊匹配相邻的单元格?