Simple macro ends after loop?

patriot333

New Member
Joined
Mar 28, 2009
Messages
3
The following are two examples of a macro that simply end after the loop. They seem to complete the loop properly, but instead of continuing on with the rest of the code it ERRORs out?
I just need it to then go to the "RegCard" sheet then and stop.
Any help would be greatly appreciated. Thank you in advance.

Sub WaterCouponLoop1()
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>Application.ScreenUpdating = False
Sheets("WaterCoupons").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Do Until (Data!E2 + 10 > WaterList03!G3)
<o:p></o:p>Sheets("Data").Select
Range("E2").Select
ActiveCell.Value = 10 + ActiveCell.Value
Sheets("WaterCoupons").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Loop
Sheets("RegCard").Select
Application.ScreenUpdating = True
<o:p></o:p>
End Sub
<o:p></o:p>
<o:p></o:p>
Sub WaterCouponLoop1()
<o:p></o:p>Application.ScreenUpdating = False
Sheets("WaterCoupons").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Do
<o:p></o:p>Sheets("Data").Select
Range("E2").Select
ActiveCell.Value = 10 + ActiveCell.Value
Sheets("WaterCoupons").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Loop Until (Data!E2 > WaterList03!G3)
Sheets("RegCard").Select
Application.ScreenUpdating = True
<o:p></o:p>
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
It would be better if you described in words what you are trying to do rather than posting vba code which may (or may not) convey that message.

As a side note, you do not need to .Select Excel objects in vba to work with them.
 
Upvote 0
I posted the code so the code itself could be checked for errors.

Thanks for the review, I went with another loop variant. I'll post it here for posterity:

Sub WaterCouponLoop1()
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
Application.ScreenUpdating = False
Sheets("WaterCoupons").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Dim i As Integer
Dim intValue As Integer
intValue = Range("WaterList03!G6")
For i = 1 To intValue
Sheets("Data").Select
Range("E2").Select
ActiveCell.Value = 10 + ActiveCell.Value
Sheets("WaterCoupons").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Next i
<o:p> </o:p>
Sheets("Data").Select
Range("E2").Select
ActiveCell.Value = 1
Sheets("RegCard").Select
Application.ScreenUpdating = True
<o:p> </o:p>
End Sub
 
Upvote 0
What error does it give?

Is it "Subscript Out Of Range" ?

If so, that means either...
The sheet "RegCard" does not exist (check exact spelling, and look for extra spaces).
Or
The sheet "RegCard" is Hidden. (A sheet must be visible in order to be selected).

To solve that, unhide the sheet first, then select it

Sheets("RegCard").Visible = True
Sheets("RegCard").Select
 
Upvote 0
Thank you very much for the time you took to respond to my question. I did get it to work by using the code in my last post.

Thanks again,

-Tom
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top