The code (with the SumOffset1) works perfectly and gives the correct result in the cell(5,2) running the function which it starts from the cell(3,3).Could you please help me how to modify the function so as to get the correct result in the cell(5,3) and the function starting from the cell(3,4) and so on.
Sub commulative()
Dim i As Integer
For i = 0 To 5
If Cells(4, 2) <= SumOffset1(i) Then
Cells(5, 2) = (i - 1) * 5 + (Cells(4, 2) - SumOffset1(i - 1)) / (Cells(3, i + 2) / 5)
Exit For
End If
Next i
End Sub
Function SumOffset1(iteration As Integer) As Double
Dim sum As Double
Dim j As Integer
For j = 1 To iteration
sum = sum + Cells(3, 2).Offset(0, j)
Next j
SumOffset1 = sum
End Function
With the above code the function summaries only the cells from (3,2) and (3,3) etc.I d like to have something as is below but it doesn’t work:
Sub commulative()
Dim i As Integer
For i = 0 To 5
If Cells(4, k) <= SumOffset1(i) Then
Cells(5, k)= (i - 1) * 5 + (Cells(4, k) - SumOffset1(i - 1)) / (Cells(3, i + k) / 5)
Exit For
End If
Next i
End Sub
Function SumOffset1(iteration As Integer) As Double
Dim sum As Double
Dim j As Integer
For j = 1 To iteration
sum = sum + Cells(3, k).Offset(0, j)
Next j
SumOffset1 = sum
End Function