#1   Report Post  
Posted to microsoft.public.excel.programming
bob bob is offline
external usenet poster
 
Posts: 3
Default Loop error

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Loop error

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.


On Sep 30, 4:24*pm, "bob" wrote:
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
bob bob is offline
external usenet poster
 
Posts: 3
Default Loop error

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

Bob
"FunkySquid" wrote in message
...
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.


On Sep 30, 4:24 pm, "bob" wrote:
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Loop error

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


On Sep 30, 11:24*am, "bob" wrote:
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


  #5   Report Post  
Posted to microsoft.public.excel.programming
bob bob is offline
external usenet poster
 
Posts: 3
Default Loop error

Works fine now thanks all for your help

Bob
"Susan" wrote in message
...
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


On Sep 30, 11:24 am, "bob" wrote:
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Loop error

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


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"bob" wrote in message
...
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


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
Error for loop Daniel Excel Programming 0 January 3rd 08 07:14 PM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM
Error in loop Daniel Bonallack[_2_] Excel Programming 2 November 19th 03 07:10 PM
loop error Sam Excel Programming 1 September 18th 03 03:09 PM
loop error Sam Excel Programming 0 September 18th 03 02:19 PM


All times are GMT +1. The time now is 11:12 AM.

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

About Us

"It's about Microsoft Excel"