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 ?
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 ?
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.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Yep, count1 is worth 25.
When I tested it with count1 = 6 and Cells(5,9) = 3 I got res1 changing fine.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
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