Exit Sub when Cancel is Pressed

evil_moses

New Member
Joined
Oct 27, 2008
Messages
39
Hi,

I have the below macro set up to filter 7 tabs by a user defined entry, choose a printer and then print those tabs, before removing all the filters and going back to the original screen. Works fine, except for when the user hits cancel on the first input box. If cancel is pressed then the macro continues but filters the tabs by "False", whereas I of course want the macro to stop if this option is selected.

I have tried using:
If iReply = False Then Exit Sub
but this seems to exit sub no matter what is entered.

Can anyone help? There are many different entries the user could enter, so I cannot just use If iReply <> .....

Thanks a lot

Marcus

Sub Filter_By_Consultant()
'

Dim iReply As String
Dim ActPrinter As String
Dim Answer As Boolean
iReply = Application.InputBox(Prompt:="Please enter the name of the Consultant whose Pipeline you wish to print:")
Sheets("Schedule PA").Select
Selection.AutoFilter Field:=3, Criteria1:=iReply
Sheets("Await PA").Select
Selection.AutoFilter Field:=3, Criteria1:=iReply
Sheets("Schedule SC").Select
Selection.AutoFilter Field:=3, Criteria1:=iReply
Sheets("Await SC").Select
Selection.AutoFilter Field:=3, Criteria1:=iReply
Sheets("Schedule Procedure").Select
Selection.AutoFilter Field:=3, Criteria1:=iReply
Sheets("Await Procedure").Select
Selection.AutoFilter Field:=3, Criteria1:=iReply
Sheets("Validate").Select
Selection.AutoFilter Field:=3, Criteria1:=iReply
Sheets(Array("Schedule PA", "Await PA", "Schedule SC", "Await SC", _
"Schedule Procedure", "Await Procedure", "Validate")).Select
With Application
ActPrinter = .ActivePrinter
Answer = .Dialogs(xlDialogPrinterSetup).Show
End With
If Answer = False Then
Sheets("Schedule PA").Select
Selection.AutoFilter Field:=3
Sheets("Await PA").Select
Selection.AutoFilter Field:=3
Sheets("Schedule SC").Select
Selection.AutoFilter Field:=3
Sheets("Await SC").Select
Selection.AutoFilter Field:=3
Sheets("Schedule Procedure").Select
Selection.AutoFilter Field:=3
Sheets("Await Procedure").Select
Selection.AutoFilter Field:=3
Sheets("Validate").Select
Selection.AutoFilter Field:=3
Sheets("Menu").Select
Exit Sub
Else
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.ActivePrinter = ActPrinter
Sheets("Schedule PA").Select
Selection.AutoFilter Field:=3
Sheets("Await PA").Select
Selection.AutoFilter Field:=3
Sheets("Schedule SC").Select
Selection.AutoFilter Field:=3
Sheets("Await SC").Select
Selection.AutoFilter Field:=3
Sheets("Schedule Procedure").Select
Selection.AutoFilter Field:=3
Sheets("Await Procedure").Select
Selection.AutoFilter Field:=3
Sheets("Validate").Select
Selection.AutoFilter Field:=3
Sheets("Menu").Select
End If
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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