我想遍歷整個列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
什麼是「EdgePos」?它從哪裏獲得它的價值? – Jeeped
Edgepos從B23行獲取它的值。 –
其在我的xl電子表格上的邊緣位置的邊框 –