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
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