while loop

  • Thread starter Thread starter Arun Kumar Saha
  • Start date Start date
A

Arun Kumar Saha

can anyone tell me what is the wrong with this loop? Excel is not going
inside this loop.

Do While R(j).Value < R(j - 1).Value And j > 1
k = 1
temp = R(j).Value
R(j).Value = R(j - 1).Value
R(j - 1).Value = temp
j = j - 1
Loop


Thanks
 
try
While R(j).Value < R(j - 1).Value And j > 1
k = 1
temp = R(j).Value
R(j).Value = R(j - 1).Value
R(j - 1).Value = temp
j = j - 1
wend

I assume some where above you set J greater than 1
or it will not do the loop
Why is K = 1 in the loop? it is not used
 
bj has given the answer: one of the two tests is failing, which means that
either R(j).Value is equal to or greater than R(j-1).Value or j is greater
than 1 when it gets to the Do While statement - in either case the sort
inside of the loop won't get carried out. Same question about k=1: why do it
over and over again inside of the loop and not use it within the loop?

You need to examine the tested values at the Do While statement to see what
is not as expected. Either make that line a breakpoint or put a Stop
statement just ahead of it so you can use the Immediate Window in the VB
Editor to examine those values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top