#1   Report Post  
Junior Member
 
Posts: 10
Default while loop

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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
bj bj is offline
external usenet poster
 
Posts: 1,397
Default while loop

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



"Arun Kumar Saha" wrote:


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




--
Arun Kumar Saha

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,365
Default while loop

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.

"Arun Kumar Saha" wrote:


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




--
Arun Kumar Saha

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop Heather O'Malley Excel Discussion (Misc queries) 1 November 6th 06 02:39 PM
How would I add a loop for this? [email protected] Excel Discussion (Misc queries) 3 September 18th 06 01:21 PM
loop Wanna Learn Excel Discussion (Misc queries) 14 September 1st 06 12:36 AM
Any way to loop this in VBA? Bill (Unique as my name) Excel Discussion (Misc queries) 5 February 22nd 06 11:04 PM
Please help with loop Mike C Excel Discussion (Misc queries) 3 January 29th 05 02:31 PM


All times are GMT +1. The time now is 08:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"