#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Leave loop

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Leave loop

If I understand your question correctly, execute an

Exit For

statement right after your Past statement.

--
Rick (MVP - Excel)


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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Leave loop

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


On Oct 15, 1:37*pm, wrote:
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Leave loop

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)


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


On Oct 15, 1:37 pm, wrote:
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


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
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
Leave Log CiceroCF Excel Discussion (Misc queries) 1 January 10th 07 07:25 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Leave last col alone Bob Phillips[_5_] Excel Programming 0 September 1st 03 02:38 PM


All times are GMT +1. The time now is 02:35 PM.

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

About Us

"It's about Microsoft Excel"