Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Do Until Loop

I'd like the following loop to exit when there are no additional sheets
availble. Please help.

Do Until ActiveSheet.Next = False

Windows("Primary GBT Prod_Breakdown " & MyValue & ".xls").Activate
Selection.Copy
Windows("Agency Prime Gross Plotting by Placement " & MyValue &
".xls").Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Windows("Primary GBT Prod_Breakdown " & MyValue & ".xls").Activate
ActiveCell.Offset(22, 0).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Agency Prime Gross Plotting by Placement " & MyValue &
".xls").Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
For b = 1 To 11
Windows("Primary GBT Prod_Breakdown " & MyValue & ".xls").Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Agency Prime Gross Plotting by Placement " & MyValue &
".xls").Activate
ActiveCell.Offset(-1, 2).Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Next b
ActiveCell.Offset(64, -23).Range("A1").Select
Windows("Primary GBT Prod_Breakdown " & MyValue & ".xls").Activate
ActiveSheet.Next.Select

Loop
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Do Until Loop

Hargrove,

Instead of a do loop, I think you're better off using a For Each Next.
Here's a simple example that excludes the first sheet:

Sub test()

Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
If sh.Name < "Sheet1" Then
MsgBox sh.Name
End If
Next sh

End Sub

hth,

Doug Glancy
"Hargrove" wrote in message
...
I'd like the following loop to exit when there are no additional sheets
availble. Please help.

Do Until ActiveSheet.Next = False

Windows("Primary GBT Prod_Breakdown " & MyValue & ".xls").Activate
Selection.Copy
Windows("Agency Prime Gross Plotting by Placement " & MyValue &
".xls").Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,

SkipBlanks:= _
False, Transpose:=False
Windows("Primary GBT Prod_Breakdown " & MyValue & ".xls").Activate
ActiveCell.Offset(22, 0).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Agency Prime Gross Plotting by Placement " & MyValue &
".xls").Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,

SkipBlanks:= _
False, Transpose:=False
For b = 1 To 11
Windows("Primary GBT Prod_Breakdown " & MyValue & ".xls").Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Agency Prime Gross Plotting by Placement " & MyValue &
".xls").Activate
ActiveCell.Offset(-1, 2).Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,

SkipBlanks:= _
False, Transpose:=False
Next b
ActiveCell.Offset(64, -23).Range("A1").Select
Windows("Primary GBT Prod_Breakdown " & MyValue & ".xls").Activate
ActiveSheet.Next.Select

Loop



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Do Until Loop

If you want to keep your existing code, you could use error trapping to exit
the loop. Notice there are no conditions on either the Do or Loop statements.

Do
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
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 PM
Loop desmondleow[_10_] Excel Programming 1 December 26th 03 01:32 PM
How to get out of loop ???? Ray Batig Excel Programming 3 December 24th 03 11:00 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 03:47 AM.

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"