I am trying to loop through a column in excel using VBA, am having a problem because has "W2" hard coded in the function so as I iterate through the spreadsheet, the W2 needs to change to W3, W4 W5 etc.
below is my code.
Function GetTopDrTS(L_NumCellsFromEdge As Integer, L_NumOfCells As Integer) As Double
'Get Top Drive Side Triple Spot calculation
Dim val As Double
val = 0
'Select Cell W2 to set starting position
Range("W2").Select
'Read in the cells we need to average
Dim i As Integer
For i = 0 To L_NumOfCells - 1
val = val + Selection.Worksheet.Cells(Selection.Row, _
Selection.Column + EdgePos + L_NumCellsFromEdge + i).Value
Next i
GetTopDrTS = val / L_NumOfCells
end function