Search:

Nested For Loop Plz Help

Asked By: Pedro    Date: Sep 29    Category: MS Office    Views: 2232

I am trying to change 2 varialbes at the same time. One variable is
used in a calculation(i) and another variable is used to define a
cell to paste the data in (j)

Here is my thought

Dim i = integer
Dim j = integer

For i = 440 to 600 step 5
For j = 1 to 500 step 1
Range ("A10").select
Formular R1C1 = (i)
'Copy range which is function of cell a10
Paste in a new sheet in column j
next j
next i

This does not do what I want, it loops through j for a given i.

So I want run case i, and paste the results in col j.
Then run case i+5,and paste in j+1
Then run cas i +10 and paste in j+2 etc.

I hope I have explained this well enough.

Share:

I'm not sure I understand exactly what you are trying to do, but I think you
just need to increase j by one each pass through the loop  - I don't think you
need a nested  loop. Have you tried replacing inside loop with j = j+1?

For j = 1 to 500
i = 440 + (j - 1) * 5
Next

Doesn't seem to be quite what you want because j will run from 1 to 500,
while I will run from 440 to 2935, and you said you only need i to run
from 440 to 600, so I'm a little confused.

I agree with Doreen - you don't want two loops, just one, and then
calculate one value based on the other.

You can also try incrementing i at the same time  you increment j like
this:

i = 440
For j = 1 to 500
i = i + 5 ' now increment i
Next

Maybe you can explain what you need to do a little more clearly?

I just need to increment j in the i loop. I
fell kind of dumb after seeing this answer, but that is what

Didn't find what you were looking for? Find more on Nested For Loop Plz Help Or get search suggestion and latest updates.

Tagged: