Sum up the results inside a FOR loop

makiwara

Board Regular
Joined
Mar 8, 2018
Messages
133
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:

Some videos you may like

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
Joined
Apr 18, 2011
Messages
36,313
Office Version
  1. 2010
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,020
Messages
5,526,296
Members
409,694
Latest member
bastos21

This Week's Hot Topics

Top