Compile error with Do Until Loop query.

shumba

Board Regular
Joined
Oct 5, 2010
Messages
168
Hi,

In the procedure below a compile error message “ Loop without Do” is being generated in the first Do Until Loop structure. This procedure has been working well previously. The Excel workbook is receiving real time data from an online server.


Could this be an issue with the server or Excel itself?



Code:
Sub Analyse()
      Application.ScreenUpdating = False
      'checks if the traded value has exceeded the Set Value
      'and todays low is greater than yesterdays low
      'and todays volume is greater than the previous five days
      Sheets("Market Interface").Select
      Range("p4").Select
      Do Until IsEmpty(ActiveCell)
      If Selection.Offset(0, -4).Value > Selection.Offset(0, -3).Value And _
      Selection.Offset(0, 24).Value > 0 Then
      Selection.Offset(0, -2).Copy Sheets("Selections").Range("b:b").Cells(Rows.Count).End(xlUp).Offset(1, 0)
      Selection.Offset(1, 0).Select
      Loop
      
      'puts the time when the stock was selected into column B
      Sheets("Selections").Select
      Range("a9").Select
      Do Until IsEmpty(Selection.Offset(0, 1).Value)
      Range("a:a").Cells(Rows.Count).End(xlUp).Offset(1, 0).Select
      If Not IsEmpty(Selection.Offset(0, 1)) Then Selection.Value = Now
      Loop
   
  '    Range("c9").Select
  '
  '    'copies the code to column C in preperation to download RTD
  '    Do Until IsEmpty(Selection.Offset(0, -1).Value)
  '    Range("c:c").Cells(Rows.Count).End(xlUp).Offset(1, 0).Select
  '    If Not IsEmpty(Selection.Offset(0, -1)) Then Selection.Value = Range("A" & ActiveCell.Row)
  '    Loop
   
      'deletes the codes that are duplicated up the list
      Call Check_for_previous_occurance_of_code
  End Sub
Any help will be much appreciated.

Thanks. Rob.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Rob

I don't know how what you describe could have happened - the code as is just wouldn't compile because you are missing an End If within the first loop.

This will compile:
Rich (BB code):
   Do Until IsEmpty(ActiveCell)
        If Selection.Offset(0, -4).Value > Selection.Offset(0, -3).Value And _
           Selection.Offset(0, 24).Value > 0 Then
            Selection.Offset(0, -2).Copy Sheets("Selections").Range("b:b").Cells(Rows.Count).End(xlUp).Offset(1, 0)
            Selection.Offset(1, 0).Select
        End If
    Loop
 
Upvote 0
Oops, might have posted code that could send you into an endless loop.

The End If should be before the Offset.

I've also added a reference to the range, you don't really need to use Select.
Code:
 Set rng = Sheets("Market Interface").Range("p4")
    Do Until IsEmpty(rng)
        If rng.Offset(0, -4).Value > rng.Offset(0, -3).Value And rng.Offset(0, 24).Value > 0 Then
            rng.Offset(0, -2).Copy Sheets("Selections").Range("b:b").Cells(Rows.Count).End(xlUp).Offset(1, 0)
        End If
        Set rng = rng.Offset(1, 0)
    Loop
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top