I want to loop through an entire column
W2, while taking the average of each row. the column is 1326 long.
The code I have below only calculates the average of
B2. Can someone help
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
This is all you need: