0

The below code (with the SumOffset1 Function) works perfectly and gives the result in the Cell (5,2) correctly. How can I continue the same Loop giving the correct result in the {Cell (5,2) (by using the sum function starts from the cell(3,3)}, then the same Loop giving result in the {Cell (5,3) (by using the sum function starts from the cell(3,4)} and so on: the same Loop giving result in the {Cell (5,k) (by using the sum function starts from the cell(3,k)}.

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

What I would like to descripe is the below

enter image description here

Mayukh Bhattacharya
  • 12,541
  • 5
  • 21
  • 32
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 01 '23 at 11:11

0 Answers0