看着上图,我想知道如何找到从符合特定条件的数字开始的平均值?例如,给定范围 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/