Sum up the results inside a FOR loop

makiwara

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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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.
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top