#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 40
Default Cancel/Exit Sub

This code works but, how can I exit this code if I hit "Cancel" or "OK?"
Field (column) 7 has either a yes or a no in the cell.

With ActiveSheet
.UsedRange.AutoFilter Field:=7, Criteria1:=InputBox(prompt:="Enter
Yes or No")
.PageSetup.Orientation = xlLandscape
.PrintOut
.UsedRange.AutoFilter
End With
Range("A1").Select

Thanks,
--
Howard
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default Cancel/Exit Sub

myFilter = InputBox(prompt:="Enter Yes or No")
If myFilter = "" Then
'User did not enter anything or hit cancel
msgbox "Please enter Yes or No",vbinformation
exit sub
End If

With ActiveSheet
.UsedRange.AutoFilter Field:=7, Criteria1:=myFilter
.PageSetup.Orientation = xlLandscape
.PrintOut
.UsedRange.AutoFilter
End With
Range("A1").Select

Thanks,
--
Howard

"Howard" wrote:

This code works but, how can I exit this code if I hit "Cancel" or "OK?"
Field (column) 7 has either a yes or a no in the cell.

With ActiveSheet
.UsedRange.AutoFilter Field:=7, Criteria1:=InputBox(prompt:="Enter
Yes or No")
.PageSetup.Orientation = xlLandscape
.PrintOut
.UsedRange.AutoFilter
End With
Range("A1").Select

Thanks,
--
Howard

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Cancel/Exit Sub

myFilter = InputBox(prompt:="Enter Yes or No")

In this case it would be better to use a MsgBox.

Dim Res As VbMsgBoxResult
Res = MsgBox("Click yes or no.")
If Res = vbYes Then
' user clicked Yes
Else
' user clicked No
End If

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

On Tue, 16 Dec 2008 13:36:01 -0800, Brotha Lee
wrote:

myFilter = InputBox(prompt:="Enter Yes or No")
If myFilter = "" Then
'User did not enter anything or hit cancel
msgbox "Please enter Yes or No",vbinformation
exit sub
End If

With ActiveSheet
.UsedRange.AutoFilter Field:=7, Criteria1:=myFilter
.PageSetup.Orientation = xlLandscape
.PrintOut
.UsedRange.AutoFilter
End With
Range("A1").Select

Thanks,
--
Howard

"Howard" wrote:

This code works but, how can I exit this code if I hit "Cancel" or "OK?"
Field (column) 7 has either a yes or a no in the cell.

With ActiveSheet
.UsedRange.AutoFilter Field:=7, Criteria1:=InputBox(prompt:="Enter
Yes or No")
.PageSetup.Orientation = xlLandscape
.PrintOut
.UsedRange.AutoFilter
End With
Range("A1").Select

Thanks,
--
Howard

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 40
Default Cancel/Exit Sub

Excellent! Thanks very much.
--
Howard


"Brotha Lee" wrote:

myFilter = InputBox(prompt:="Enter Yes or No")
If myFilter = "" Then
'User did not enter anything or hit cancel
msgbox "Please enter Yes or No",vbinformation
exit sub
End If

With ActiveSheet
.UsedRange.AutoFilter Field:=7, Criteria1:=myFilter
.PageSetup.Orientation = xlLandscape
.PrintOut
.UsedRange.AutoFilter
End With
Range("A1").Select

Thanks,
--
Howard

"Howard" wrote:

This code works but, how can I exit this code if I hit "Cancel" or "OK?"
Field (column) 7 has either a yes or a no in the cell.

With ActiveSheet
.UsedRange.AutoFilter Field:=7, Criteria1:=InputBox(prompt:="Enter
Yes or No")
.PageSetup.Orientation = xlLandscape
.PrintOut
.UsedRange.AutoFilter
End With
Range("A1").Select

Thanks,
--
Howard

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
Exit Code Upon Cancel On Type 8 Input Box FARAZ QURESHI Excel Discussion (Misc queries) 2 March 31st 08 09:22 AM
InputBox / VBA question ok = print, cancel = exit todd78 Excel Worksheet Functions 4 August 9th 07 04:42 PM
cancel input ME @ Home Excel Discussion (Misc queries) 1 February 22nd 06 09:49 AM
can I cancel a save juls!1601 Excel Discussion (Misc queries) 2 February 16th 06 01:03 AM
Read Only - How to Cancel? Glenn Excel Discussion (Misc queries) 1 August 26th 05 06:23 PM


All times are GMT +1. The time now is 01:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"