cancel the loop

G

Guest

I have set up a loop to prepare selected reports for appropriate location(s).
When I have printed all of the reports I want and select "CANCEL", how do I
set up the program to cancel the loop?

'
Dim iResult As Integer

Sheets("Mail List").Select
Do
iResult = InputBox("Please enter the Store Number:")
Range("a15").Value = iResult
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Loop

End Sub

Thanks in advance!!!
 
D

Dave Peterson

do
iresult = inputbox(...)
if trim(iresult) = "" then
exit do
end if
'rest of stuff
loop
 
R

Ron de Bruin

Try this

You can also use the test if the inputbox have a value if you want
See two commented code lines in the macro

Sub test()
Dim iResult

Sheets("Mail List").Select
Do
iResult = Application.InputBox("Please enter the Store Number:")
If iResult = False Then Exit Do
'If iResult <> "" Then
Range("a15").Value = iResult
ActiveWindow.SelectedSheets.PrintOut preview:=True
'End If
Loop

End Sub
 

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

Similar Threads

Loop error 5
Input box cancel 1
odd issue with a loop 3
Printing Macro 4
For/Next Loop 2
Printing Macro 1
Assigned macro in Dialog giving error 9
macro to print a sheet if a cell is a certain value 1

Top