Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Do....Loop Woes (xp)

    I have four Do .... Loop procedures of the form:
    Sub MoveUp
    Do Until ActiveCell.Offset(-1, 0).Interior.ColorIndex = 1
    ActiveCell.Offset(0, 1).Value = "l"
    ActiveCell.Offset(0, 1).Select
    Loop
    End Sub

    which individually work fine.

    I am trying to incorporate them into another loop statement but I keep getting a Loop without Do error in the following code:

    Sub MoveLRDU()

    Sheets("Sheet1").Activate

    Do Until Range("B23").Value = "l"

    If ActiveCell.Offset(0, -1).Interior.ColorIndex <> 1 Then
    MoveLeft2

    If ActiveCell.Offset(0, 1).Interior.ColorIndex <> 1 Then
    MoveRight

    If ActiveCell.Offset(1, 0).Interior.ColorIndex <> 1 Then
    MoveDown2

    If ActiveCell.Offset(-1, 0).Interior.ColorIndex <> 1 Then
    MoveUp

    Loop

    End If

    End Sub

    Presumably I am committing a basic sin.

    Help would be appreciated.
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

  2. #2
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    268
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Do....Loop Woes (xp)

    Rob - a couple of things:
    <UL><LI> The series of <font color=blue>If Then</font color=blue> statements each need to be terminated with an <font color=blue>End If</font color=blue>.
    <LI>If the <font color=blue>MoveLeft2</font color=blue> routines are like the <font color=blue>MoveUp</font color=blue> routine, then you will be re-setting the active cell when each of the subroutines are executed, and then re-entering the comparison routine somewhere in the middle. While this may do what you wish, I suspect that it will be error-prone; you might want to use a <font color=blue>Select Case</font color=blue> construct instead, since it will 'drop out' of the comparison stack after a successful comparison so the loop will repeat from the top. This may require that you define the activecell.colorindex as a variable and then use the value of the variable in the <font color=blue>Select Case</font color=blue> statement; I can't remember and am just running air code here.
    <LI>The final <font color=blue>End If</font color=blue> statement does not refer to a prior <font color=blue>If Then</font color=blue> that I can see.[/list]

  3. #3
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Do....Loop Woes (xp)

    Thanks Dean,

    The End Ifs were causing the problem.
    It works now!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •