[英]Using excel, how do you calculate the average occurrence of the same numbers in a column?
[英]How do I calculate the average of different ranges in the same column in Excel preferably using command button?
我正在使用Excel2013。大約有五十個工作表,我必須計算工作表中的數百個平均值。 數據像C3:C10,C12:C16,C18:C35等那樣散布,我想計算每個范圍(如C11,C17,C36等)末尾的平均值。范圍始終在同一范圍內列,每個范圍由兩個空白單元格分隔,但范圍不是固定的。
我嘗試錄制宏。
Sub Averaging()
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-12]C:R[-1]C)"
End Sub
但是我不知道如何使R [-12] C零件動態化。 我正在考慮創建一個命令按鈕,在選擇單元格后,例如范圍是C3:C10,然后選擇單元格C11,然后按下命令按鈕,它將自動選擇范圍並計算平均值。 可能嗎?
任何幫助將不勝感激。 VBA,任何公式。
你可以用
Sub WriteAverage(columnRng As Range)
Dim iArea As Long
With columnRng.Columns(1).SpecialCells(xlCellTypeConstants, xlNumbers).Areas
For iArea = 1 To .Count
With .Item(iArea).Cells
.Offset(.Rows.Count).Resize(1).FormulaR1C1 = "=average(R" & .Cells(1, 1).Row & "C:R[-1]C)"
End With
Next iArea
End With
End Sub
被稱為如下
Call WriteAverage(Columns("C"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.