I am new to VBA - trying to do a simple calculation using VBA but not able to make it work properly. Any help will be highly appreciated. Basically I have a row, the result should be equal to the previous result + current according cell
This is what I mean
A | B | C | D | |
---|---|---|---|---|
(1)Row 1 | 1 | 2 | 3 | 4 |
(2)Result | 1 | (1+2) | (1+2)+3 | ((1+2)+3)+4 |
I've been using for Next but wasn't able to generate the result I want to see, the first output is correct, but after the first calculation, all the ongoing calculation is incorrect
Sub DeltaAllocationToCRSSum()
Range("A2").Value = 1 ' Set starting value for the first cell in the result roll
Dim Column1 As Integer
Dim Column2 As Integer
For Column1 = 1 to 4
For Column2 = 2 To 5
Cells(2,Column2) = Cells(2,Column1)+Cells(1,Column2) 'meaning B2 = A2 + B1 for the first calculation
Next Column2
Next Column1
So this code was able to get me the right result for the first calculation always, but the consecutive result are always wrong. Anybody know what is the issue? Sorry this question maybe very basis, but I can't figure it out myself.... Thank you for helping