DougR21
08-13-2021, 06:49 AM
Hi! I'm trying to code a macro to perform a cumulative sum. The starts is in the cell D1 and the first value is the cell A1 to the value of cell A2, and adds up to the value of cell C1. The problem is that when I run this macro it seems to me that it is in an infinite loop. Below is the macro code:
Sub CumSum ()
Dim W As Worksheet
Dim Min As Integer
Dim Max As Integer
Dim Cum As Integer
Set W = Sheets("Plan1")
Min = W.Range("A1").Value
Max = W.Range("A2").Value
Cum = W.Range("B1").Value
W.Range("D1").Value = Min
W.Select
W.Range("D1").Select
Do Until Min = Max
Min = Cum + ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Loop
End Sub
And a worksheet screenshot with the values in the cells for example:
https://i.ibb.co/McPRb3C/Imagem1.png (https://imgbb.com/)
If anyone can point out the error to me, how to fix it, and if there is more efficient code for this macro's function, I would be immensely grateful.
Sub CumSum ()
Dim W As Worksheet
Dim Min As Integer
Dim Max As Integer
Dim Cum As Integer
Set W = Sheets("Plan1")
Min = W.Range("A1").Value
Max = W.Range("A2").Value
Cum = W.Range("B1").Value
W.Range("D1").Value = Min
W.Select
W.Range("D1").Select
Do Until Min = Max
Min = Cum + ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Loop
End Sub
And a worksheet screenshot with the values in the cells for example:
https://i.ibb.co/McPRb3C/Imagem1.png (https://imgbb.com/)
If anyone can point out the error to me, how to fix it, and if there is more efficient code for this macro's function, I would be immensely grateful.