View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default VBA code for MsgBox

You don't want to advise the user to try again if he has just done a Cancel,
so you will either have to pick up the False from Application.Msgbox or
use StrPtr(strVar) = 0 with Msgbox.

RBS


"Gord Dibben" <gorddibbATshawDOTca wrote in message
...
Sub test()
Dim result As Long
On Error GoTo endit
result = InputBox("Enter Number of Days which are in this" & vbLf & _
"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 from 1 to 3"

End Select
Exit Sub
endit:
MsgBox "You pressed Cancel or did not enter anything. Try again"
End Sub

Application.InputBox usually reserved for selecting ranges using mouse or
typed
reference.


Gord Dibben MS Excel MVP

On Sun, 1 Jun 2008 14:14:00 -0700, Chris D

wrote:

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?