# Sum up the results inside a FOR loop

#### makiwara

##### Board Regular
Hi! I have a code but it doesn't do what It should :D

Code:
``````For h = 0 To k  'lets suppose from 1 to 4

capital = 400 * 3 ^ h
ossz = 0 + capital
Next``````

I would like to sum up 400, 1200, 3600, and 10800, but the "ossz" variable is always the latest value of capital. So at the end of the loop it's 3600, instead of 16.000

Thank you for your help! Have a nice day!

Last edited:

### Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

#### Rick Rothstein

##### MrExcel MVP
Hi! I have a code but it doesn't do what It should :D

Code:
``````For h = 0 To k  'lets suppose from 1 to 4

capital = 400 * 3 ^ h
[B][COLOR="#FF0000"]ossz = 0 + capital[/COLOR][/B]
Next``````

I would like to sum up 400, 1200, 3600, and 10800, but the "ossz" variable is always the latest value of capital. So at the end of the loop it's 3600, instead of 16.000

Try changing the red highlighted line of code to this...

ossz = ossz + capital

so that each new calculated capital value is added to the total of the previous capital values.

Replies
0
Views
77
Replies
6
Views
86
Replies
1
Views
38
Replies
3
Views
56
Replies
2
Views
212