View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones[_2_] Norman Jones[_2_] is offline
external usenet poster
 
Posts: 421
Default VBA code for MsgBox

Hi Chris,

Try changing your result variable to a
variant, which will wenabl you to trap a
cancel operation.

Try, therefo

'==========
Public Sub Tester()
Dim result As Variant

result = Application.InputBox _
("Enter Number of Days" _
& " which are in this report" _
& "( highest number of worksheets in " _
& "document", "Days in Report")

Select Case result
Case 1
Columns("T:CJ").Select
Case 2
Columns("U:CJ").Select
Case 3
Columns("V:CJ").Select
Case False
Exit Sub
Case Else
MsgBox "please enter a valid number"

End Select

End Sub
'<<==========



---
Regards.
Norman
"Chris D" wrote in message
...
For the following script I get an inputbox for which the user has to enter
a
number:
Dim result As Long

result = Application.InputBox("Enter Number of Days which are in this
report( highest number of worksheets in document", "Days in Report")

Select Case result
Case 1
Columns("T:CJ").Select
Case 2
Columns("U:CJ").Select
Case 3
Columns("V:CJ").Select
Case Else
MsgBox "please enter a valid number"

End Select

I would like the macro to exit the sub when "cancel" is selected.
Can anyone help me with this?