Loop error

B

bob

Hi I have the following code which I need to Loop but it keeps coming up
with the following error

Compile Error Loop Without Do

Can you see where I have gone wrong? I do have a Do Until statement, if I
take out the word Loop out it comes up with the Error
Compile Error Do Without Loop what's wrong?

Sheets("Data").Select
Range("A2").Select
Do Until ActiveCell = ""
If ActiveCell > "" Then
Selection.Copy
Sheets("Advice").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Advice").Select
If Range("P51") > 0 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
Sheets("Data").Select
ActiveCell.Offset(1, 0).Range("A1").Select
Loop
End If
Exit Do
Sheets("Lookup").Select

End Sub


Thanks Bob
 
F

FunkySquid

It's the last few lines that look wrong. You have an Exit Do outside
the loop & the End If outside the loop. Try this:


Sheets("Data").Select
Range("A2").Select
Do Until ActiveCell = ""
If ActiveCell > "" Then
Selection.Copy
Sheets("Advice").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Advice").Select

If Range("P51") > 0 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

Sheets("Data").Select
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Loop
'Exit Do
Sheets("Lookup").Select


Hope this helps.
 
S

Susan

A. it would help greatly if you indented your code (see below)

B. your second "end if" needs to be within the loop (i believe).

hope that helps
:)
susan
 
B

bob

No that make no difference it still comes up with the same error.

Bob
It's the last few lines that look wrong. You have an Exit Do outside
the loop & the End If outside the loop. Try this:


Sheets("Data").Select
Range("A2").Select
Do Until ActiveCell = ""
If ActiveCell > "" Then
Selection.Copy
Sheets("Advice").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Advice").Select

If Range("P51") > 0 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

Sheets("Data").Select
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Loop
'Exit Do
Sheets("Lookup").Select


Hope this helps.
 
D

Don Guillett

If you are trying to copy each cell to b4 in advice and then print advice
and then do the next

sub trythis()'untested
with Sheets("Data")
lastrow=.cells(2,"a").end(xldown).row
for each c in .range("a2:a" & lastrow)
sheets("advice").range("b4).value=c.value
sheets("advice").printout
next c
end with
end sub

Sheets("Data").Select
Range("A2").Select
Do Until ActiveCell = ""
If ActiveCell > "" Then
Selection.Copy
Sheets("Advice").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Advice").Select

If Range("P51") > 0 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

Sheets("Data").Select
ActiveCell.Offset(1, 0).Range("A1").Select
Loop
End If
Exit Do
Sheets("Lookup").Select

End Sub
 
B

bob

Works fine now thanks all for your help

Bob
A. it would help greatly if you indented your code (see below)

B. your second "end if" needs to be within the loop (i believe).

hope that helps
:)
susan
 

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

Similar Threads


Top