I am trying to create loop which is summing numbers in column N until certain value is reach then write something to cell M. I have this code working but what I actualy need is to after it found the set value to go to next row and start from 0 untill it finds again the value and then again go to next line and sum from 0 to some value.
Example of data
INV SIZE of INV
26530492 1
26530520 1
26530521 1
26530523 1
26530527 1
26530528 1
26531080 1
26531083 1
26531112 1
26531114 1
26543723 1
26543737 1
26556566 1
26556893 1
in first column are invoices and second column is showing size of the file. The loop would go throug Size column and sum rows until value is reached like 5, then it will continue until another value is reached and so on...it will also add condition to new column like first sum is number 1, second sum 2, etc..
also I am playing with code below
Sub Sum_loop()
'~~> j stands for number of summed segment
j = 1
dbSumTotal = 0
lastrow = Range("N" & Rows.count).End(xlUp).Row
For i = 2 To lastrow Step 1
'~~> in column N are numbers for sum
dbSumTotal = dbSumTotal + Cells(i, "N")
If (dbSumTotal >= 3 Or dbSumTotal <= 3) Then
Cells(i, "O") = j
'~~> reset sum to 0
If dbSumTotal >= 3 Then
dbSumTotal = 0
'~~> for next sum raise the segment number
j = j + 1
End if
End If
Next i
End Sub
.Valuethen use it.On Error Resume Nextwithout error handling! This line just hides any errors but they still occur, you just cannot see them. Remove it, or implement a proper error handling instead.OERN! It hides every error, pretending it doesn't exist. It should be used sparingly and only when you know exactly what you're doing and why you're doing it. If you permanently delete that line, you'll probably see exactly what's wrong with your code.If (dbSumTotal >= 3 Or dbSumTotal <= 3) Thenis ALWAYS true for any value ofdbSumTotalit will always be less than, equal to or greater than3. What are you really looking for?