VBA Loop without DO Error.

mcintoan

New Member
Joined
May 20, 2012
Messages
13
Heya,

Excel is coming up with an error saying: "Loop without Do", while there is a Do statement in place (as per code below). Any tips?

Effectively I want the DO Loop to run if the 2nd Cell in a row is empty for the intent to copy data into another worksheet, in addition it must skip over where the quantity in another cell is empty or 0

Cheers in advance.

Code:
Dim r As Long, sr As Long
r = 5
sr = 16


Do While Not IsEmpty(Cells(r, 2).Value)
    
    'Qnty Ignore
    If Cells(r, 3) > 0 Then
    
    'Error Checking: Item Number present?
    If Cells(r, 1).Value < 1 Then
INOINVAL:
    INo = Application.InputBox("ALDI Item No. Missing for " & Cells(r, 2).Value & " Please enter it now", Type:=1)
        
        If INo < 1 Then
        Msgbox ("Incorrect. Must be a 5 digit number")
        GoTo INOINVAL
        End If
    Cells(r, 1).Value = INo
    
    'copying text into SI
    SI.Cells(sr, 1).Value = OI.Cells(r, 1).Value
    SI.Cells(sr, 2).Value = OI.Cells(r, 2).Value
    SI.Cells(sr, 3).Value = OI.Cells(r, 3).Value
    sr = sr + 1
    t = r + 1
    End If
    Loop
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You have 3 If...Then clauses inside your Do...Loop but only two End If statements. You need another one.
 
Upvote 0
Hi

Possibly because your code is missing an End If to match the first "If Cells(r, 3) > 0 Then".
Thus it encounters the Loop statement inside the If block and doesn't have a matching Do to go with it.

Regards

Murray

 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

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