Leave loop

  • Thread starter Thread starter carlos_ray86
  • Start date Start date
C

carlos_ray86

so I have this part of the loop doing what I want.
For i = 3 To 100
Worksheets("Shapes").Range("I5:I7").Copy
If IsEmpty(Worksheets("MAG").Cells(i - 1, 1)) Then
Worksheets("MAG").Cells(i - 1, 1).PasteSpecial Paste:=xlPasteValues,
Transpose:=True

Next

However, I want it to stop right after it pastes and leave the for
loop. So basically it reads the page where ever the next blank row is
it pastes then stops. thanks
 
If I understand your question correctly, execute an

Exit For

statement right after your Past statement.
 
I tried it and it does nothing. It actually does up to the copy and
then stops..never pastes
 
It just occurs to me that you probably used a one-line If..Then statement
(as I now notice there is no End If). Change your code to this...

For i = 3 To 100
Worksheets("Shapes").Range("I5:I7").Copy
If IsEmpty(Worksheets("MAG").Cells(i - 1, 1)) Then
Worksheets("MAG").Cells(i - 1, 1).PasteSpecial _
Paste:=xlPasteValues, Transpose:=True
Exit For
End If
Next

where I have converted your one-line If..Then statement into an If..Then
block and then put the Exit For statement where I intended it to go.

--
Rick (MVP - Excel)


I tried it and it does nothing. It actually does up to the copy and
then stops..never pastes
 

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

Back
Top