需要帮助在function中循环单元格
我想遍历整个列W2
,同时取每行的平均值。 该专栏是1326长。
我下面的代码只计算W2
和B2
的平均值。 有人可以帮忙吗?
NumCellsFromEdge = 3 Dim NumOfCells As Integer NumOfCells = 3 MsgBox GetTopDrTS(NumCellsFromEdge, NumOfCells) & " = average of " & NumCellsFromEdge & " cells in, and " & NumOfCells & " cells wide" End Sub Function GetTopDrTS(L_NumCellsFromEdge As Integer, L_NumOfCells As Integer) As Double Dim val As Double Dim mycol As Double val = 0 mycol = 23 'Range("W2").Select 'Columns(mycol).Select Dim i As Integer For i = 0 To L_NumOfCells - 1 Range("W2" & i).Select val = val + Selection.Worksheet.Cells(Selection.Row, Selection.Column + EdgePos + L_NumCellsFromEdge + i).Value Next i GetTopDrTS = val / L_NumOfCells End Function
这是你需要的一切:
MsgBox [average(w:w)]
Application.average(片材(1).range( “E:E”))
将会告诉你单张1中列E的平均值