View Full Version : Solved: Why does res value stay at 1?
Hi,
I'm a C programmer, very new to VBA.
Would you help me with this very simple line of code, what's wrong ?
res = 1
For count2 = 5 To (count1 - 2)
res = res * (Cells(count2, 9).Value + 1)
Next count2
Why on earth does res stay at value 1 ? :(
Bob Phillips
09-22-2010, 04:20 AM
Have you initialised Count1? If you don't initialise it to a value greater than 6 the loop will never execute.
It will also stay at1 if the cell is empty.
Bob Phillips
09-22-2010, 06:06 AM
When I tested it with count1 = 6 and Cells(5,9) = 3 I got res1 changing fine.
got it. in my column I are the results of a previous calculation (MoM return) and for some reason, VBA consider them as 0 ....? any idea how to change that or where it comes from ?
here is the code that generates the number in column I :
For count2 = 4 To count1 - 2
Cells(count2 + 1, 9).Value = -1 + Cells(count2 + 1, 8) / Cells(count2, 8).Value
Next count2
what i mean is that for some reason, excel consider the cells are text and not numbers, any idea on how to change that ?
or maybe because some numbers have a negative value ...
solved. i declared "res" as long instead of single.
thanks for your help.
have a good day/night.
xoxo
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.